App Finishers

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:

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):

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".

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:

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?

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.