Fix guide · updated 2026-11-15
Supabase "Could not find the function in the schema cache" (PGRST202)
404 · {"code":"PGRST202","details":"Searched for the function public.get_stats with parameter userId or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.","hint":"Perhaps you meant to call the function public.get_stats(user_id)","message":"Could not find the function public.get_stats(userId) in the schema cache"}
Your app calls a database function with supabase.rpc() and gets a 404: "Could not find the function public.get_stats(userId) in the schema cache", code PGRST202. Yet the function is right there in your database. PostgREST, the part of Supabase that answers database requests, looks a function up by its name and by the names of the arguments you send. If either one is off, it can't find the function, and the message shows exactly what it searched for.
What the error means
When you call supabase.rpc('get_stats', { userId: '…' }), the keys of that object are the argument names. PostgREST looks in the public schema for a function called get_stats whose parameters match those names. Order and types don't matter here, only names. Every parameter without a default value must be sent, and every key you send must be a parameter. We tested every case below on PostgREST 14.18, the version in Supabase's self-hosted setup, and with supabase-js 2.119.0.
Read the three parts of the error:
- message: the function name, then the argument names it received, in alphabetical order. "without parameters" means no argument arrived at all.
- details: the same search in words.
- hint: often the answer. "Perhaps you meant to call the function public.get_stats(user_id)" means the name is right and gives the real parameter names. "Perhaps you meant to call the function public.get_stats" means the name was misspelled.
Then list the function's real parameters in the SQL Editor. Put your function's name, or part of it, between the % signs:
select p.oid::regprocedure as fn, pg_get_function_arguments(p.oid) as params
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.proname ilike '%stats%';
In our test it returned get_stats(text) with user_id text. A parameter that has a default shows it, for example p_points integer DEFAULT 1. No row at all: go to case 4. Two rows with the same name: case 6.
1. The argument names don't match the parameter names
This is the most common cause. The code uses camelCase (userId) and the function uses snake_case (user_id), or the function's parameters carry a prefix like p_user_id. Supabase sends your keys exactly as written; nothing converts them.
// Function: get_stats(user_id text)
// Wrong: PGRST202 "Could not find the function public.get_stats(userId)"
await supabase.rpc('get_stats', { userId: user.id });
// Right: each key is a parameter name, exactly
await supabase.rpc('get_stats', { user_id: user.id });
The same goes for the function name itself: getStats is not get_stats. In our test, both get_stat and getStats came back with the hint "Perhaps you meant to call the function public.get_stats".
2. An argument was undefined, so it was never sent
This one is easy to miss. A value that is undefined vanishes when the object is turned into JSON. A typical case is user?.id while the login session is still loading, or after the user logged out. In our test, supabase-js sent an empty {}, and the error said "Could not find the function public.get_stats without parameters". A null value is different: it is sent, and the function receives NULL.
// user is still null here: supabase-js sends {} → PGRST202 "without parameters"
await supabase.rpc('get_stats', { user_id: user?.id });
// Fix: call it only once you have the value
if (!user) return;
await supabase.rpc('get_stats', { user_id: user.id });
3. A required argument is missing, or there's an extra one
PostgREST needs exactly the parameters the function declares. You can leave one out only if it was declared with a default, and you can't add a key the function doesn't have. In our test, with add_points(p_user_id text, p_points int default 1):
{ p_user_id: 'u1' }worked:p_pointshas a default.{ p_points: 5 }failed:p_user_idhas no default.- Calling a function with no parameters while sending any key also failed (
ping({ x: 1 })).
Send exactly the parameters from the query above. If an argument should be optional, the function has to declare a default for it.
4. The function isn't in the public schema, or doesn't exist in this project
supabase.rpc() only looks in public. A function created in another schema gives PGRST202 for public.<name>, with no hint. Calling supabase.schema('private').rpc('cleanup') doesn't help unless that schema is exposed: our test got PGRST106 "Invalid schema: private".
- If your app is meant to call the function, create it in
public. - If the other schema really should be reachable, add it under "Exposed schemas" in Project Settings → Data API, and run the grants from Supabase's docs ("Using Custom Schemas"). Everything in that schema then becomes reachable through the API, so think twice for a schema named
private.
With AI-built apps, the function is often simply missing: a migration created it in the code but never ran in this Supabase project. If your code has a supabase/migrations folder, search it for the function's name and run that SQL in the SQL Editor.
5. The function was just created
PostgREST keeps the list of functions in memory: that's the "schema cache" in the message. On Supabase, creating or changing a function refreshes it by itself, through an event trigger in Supabase's Postgres (pgrst_ddl_watch). If a new function still gives PGRST202 a few seconds later, and you checked cases 1 to 4, reload the cache yourself in the SQL Editor:
notify pgrst, 'reload schema';
In our test, a function created after PostgREST started gave PGRST202 until that line ran. The next call worked.
6. "create or replace" didn't do what you expected
Two traps, both common when an AI tool edits a function:
- Renaming a parameter.
create or replacerefuses it: "cannot change name of input parameter "user_id"", with the hint "Use DROP FUNCTION get_stats(text) first." The old function stays as it was, and an app that already uses the new name gets PGRST202. If the migration ran in a tool that didn't show you that error, you never saw it fail. - Changing a parameter's type.
create or replace function get_stats(user_id uuid)doesn't replaceget_stats(user_id text): it adds a second function with the same name. In our test, the next call failed with HTTP 300, PGRST203 "Could not choose the best candidate function between: public.get_stats(user_id => text), public.get_stats(user_id => uuid)".
To rename, save the current definition, drop the function, then create it again with the new names:
-- 1. Copy the full current definition from the result
select pg_get_functiondef('public.get_stats(text)'::regprocedure);
-- 2. Drop it, then run your edited "create function" with the new parameter names
drop function public.get_stats(text);
For a duplicate, drop the version you don't want, using the types the query above showed:
drop function public.get_stats(uuid);
In our test, both fixes worked on the next call. After a drop and create, check that your users can still run the function: see 42501 below.
Which "function" error do you have?
- PGRST202 "Could not find the function … in the schema cache" (404): this page.
- PGRST203 "Could not choose the best candidate function between: …" (300): two functions share the name and the argument names. See case 6.
- 42501 "permission denied for function …" (401 or 403): the function was found, but your users' role isn't allowed to run it. In our test,
grant execute on function public.secret() to anon;fixed it (useauthenticatedfor logged-in users). - 22P02 "invalid input syntax for type integer" (400): the function was found, but a value has the wrong type, like
"lots"for a number. - PGRST106 "Invalid schema: …" (406): you called
.schema('…')on a schema that isn't exposed. See case 4. - "Edge Function returned a non-2xx status code": that's an Edge Function (
supabase.functions.invoke), not a database function. See Supabase "Edge Function returned a non-2xx status code".
Keep it from coming back
TypeScript types generated from your database include every function's argument names, so a wrong name shows up in your editor, before anyone runs the app. Supabase's docs ("Generating TypeScript Types") use the Supabase CLI:
npx supabase login
npx supabase gen types typescript --remote="<project-ref>" --schema public > database.types.ts
Then create the client with them: createClient<Database>(url, key). Generate them again after each change to a function: types from an older version of the database let the old names through.
If an AI tool built your app
Run the query from "What the error means" first, then give your AI tool this prompt with its result pasted in:
My Supabase call fails with PGRST202 "Could not find the function public.<name>(…) in the schema cache". These are the function's real parameters: <paste the query result>. Find every supabase.rpc('<name>', …) call and make each one send exactly these parameter names as keys (for example user_id, not userId), no extra keys, and never an undefined value: don't make the call until the values exist. If the function itself must change, don't use "create or replace" to rename a parameter or change its type: write the drop and create SQL, and give it to me to run myself. Don't change anything else.
Still stuck?
In your browser's developer tools, Network tab, click the failing rpc/<name> request and open its Payload. It shows the exact keys your app sent, or an empty {}. Compare them with the parameters from the query.
Other Supabase problems? See Supabase fixes.