JavaScript: Call a Postgres function

Perform a function call.

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;

To call Postgres functions on Read Replicas, use the get: true option.

Parameters

Examples

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

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

Call a Postgres function with filters

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

Call a read-only Postgres function

const \{ data, error \} = await supabase.rpc('hello_world', \{ get: true \})