Skip to main content

Postgres functions: rpc()

You can call Postgres functions as a "Remote Procedure Call".

That's a fancy way of saying that you can put some logic into your database then call it from anywhere. It's especially useful when the logic rarely changes - like password resets and updates.

const { data, error } = await supabase


  • fnrequiredstring

    The function name to call.

  • paramsoptionalundefined | object

    The parameters to pass to the function call.

  • __namedParametersrequiredobject

    No description provided.

    • headrequiredboolean

      When set to true, no data will be returned.

    • countrequirednull | exact | planned | estimated

      Count algorithm to use to count rows in a table.


Call a Postgres function

This is an example of invoking a Postgres function.

const { data, error } = await supabase

With Parameters

const { data, error } = await supabase
.rpc('echo_city', { name: 'The Shire' })

Bulk processing

You can process large payloads at once using array parameters.

const { data, error } = await postgrest
.rpc('echo_cities', { names: ['The Shire', 'Mordor'] })

With filters

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

const { data, error } = await supabase
.select('name, population')
.eq('name', 'The Shire')

With count option

You can specify a count option to get the row count along with your data. Allowed values for count option are null, exact, planned and estimated.

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