Skip to main content
Version: v2 RC

Postgres functions: rpc()

You can call Postgres functions as Remote Procedure Calls, logic in your database that you can execute from anywhere. Functions are useful when the logic rarely changes—like for password resets and updates.

create or replace function hello_world() returns text as $$
select 'Hello world';
$$ language sql;
const { data, error } = await supabase.rpc('hello_world')


  • fnrequiredFunctionName

    The function name to call

  • argsrequiredobject

    The arguments to pass to the function call

  • optionsrequiredobject

    Named parameters

    • countoptionalexact | planned | estimated

      Count algorithm to use to count rows returned by the function. Only applicable for set-returning functions.

      "exact": Exact but slow count algorithm. Performs a COUNT(*) under the hood.

      "planned": Approximated but fast count algorithm. Uses the Postgres statistics under the hood.

      "estimated": Uses exact count for low numbers and planned count for high numbers.

    • headoptionalboolean

      When set to true, data will not be returned. Useful if you only need the count.


Call a Postgres function without arguments

const { data, error } = await supabase.rpc('hello_world')

Call a Postgres function with arguments

const { data, error } = await supabase.rpc('echo', { say: '👋' })

Bulk processing

You can process large payloads by passing in an array as an argument:

const { data, error } = await supabase.rpc('add_one_each', { arr: [1, 2, 3] })

Call a Postgres function with filters

Postgres functions that return tables can also be combined with Filters and Modifiers.

const { data, error } = await supabase
.eq('id', 1)