Supabase rpc “Could not find the function … in the schema cache” and “function does not exist”

By Abheesht Tripathi · Published

{"code":"PGRST202","message":"Could not find the function public.get_orders(user_id) in the schema cache"}
ERROR: 42883: function public.get_orders(bigint) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

What it means

Two layers, two messages. PGRST202 comes from the Supabase API (PostgREST): it looked for a function with that name and those argument names and found none. 42883 comes from Postgres itself: a function with that name exists, maybe, but not one that accepts those argument types.

PGRST202: the argument names don't match

supabase.rpc() sends your arguments as a JSON object, and the API matches the keys to the function's parameter names. Positions don't matter; names must match exactly. Every key must be a parameter, and every parameter without a default must be present.

-- the function
create function public.get_orders(p_user_id uuid, p_limit int default 20) ...

// wrong: key "user_id" is not a parameter name
await supabase.rpc('get_orders', { user_id: id });

// right
await supabase.rpc('get_orders', { p_user_id: id });
await supabase.rpc('get_orders', { p_user_id: id, p_limit: 50 });

The error's details field lists the names it searched with, which makes the mismatch easy to spot.

PGRST202: other causes

PGRST203: two functions with the same name

If you created the function twice with different parameter types (for example once with int, once with bigint), the API can't choose and returns Could not choose the best candidate function between: …. Drop the version you don't need. Remember create or replace with a different argument list creates a new overload instead of replacing the old one.

42883: the argument types don't match

From SQL, triggers or other functions, Postgres matches on types. Common cases: passing a bigint to an int parameter, or a text variable to a uuid parameter. These have no implicit cast, so add one:

select public.get_orders(v_user_id::uuid, 20);

See what actually exists

select p.oid::regprocedure as signature,
       pg_get_function_identity_arguments(p.oid) as arguments
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.proname = 'get_orders';

One row with the parameter names your client sends is what you want. Two rows means an overload to drop.

Renaming parameters

create or replace function refuses to rename an existing parameter (cannot change name of input parameter). Drop the old signature first, in the same migration, then create the new one and grant execute again:

drop function if exists public.get_orders(uuid, int);
-- create function public.get_orders(...) ...
grant execute on function public.get_orders(uuid, int) to authenticated;

How to verify

The catalog query shows exactly one signature, and the same rpc() call returns data. If it now fails with permission denied for function, the function was found and only the EXECUTE grant is missing.

Related guides

More in Postgres errors and performance · all guides