JavaScript: Call a Postgres function

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;

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_city', \{ name: 'The Shire' \})

Bulk processing

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

Call a Postgres function with filters

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

Call a Postgres function with a count option

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