invalid input syntax for type uuid
Last verified:
The fix
invalid input syntax for type uuid. Postgres 22P02. The value is not a uuid. An empty string, "undefined", or "null" is the usual one. Send a real uuid or omit the filter.
- 1
Read the quoted text
The value after the colon is what the query sent.
"","undefined", and"null"mean the client stringified a missing value. A slug or a number means this column is the wrong type for that identifier, or the code passed the wrong variable. - 2
Do not query until you have a uuid
Skip the request when the id is missing. Do not coerce with
String(userId)and do not substitute"". For an insert that belongs to the signed-in user, use the session id, which is a uuid, or a column default ofauth.uid().if (!userId) { return; } const { error } = await supabase .from("todos") .select("id, title") .eq("user_id", userId); - 3
Match the column type to the value you actually have
If the app's identifier is a slug, the column should be
text, or you look up the uuid first and filter on that. Do notalterthe primary key totextin a hurry because one call passed a slug. Do not generatecrypto.randomUUID()in the browser to fill an empty filter. That queries a row that does not exist. - 4
Keep RLS and the uuid check separate
A policy that compares
auth.uid()to auuidcolumn is fine. The error is the bound value, not the policy, when the message quotes a bad string.new row violates row-level security policyis the policy page. Zero rows from.single()is PGRST116, which you only get after the uuid is valid.
Why it happens
Postgres rejects a value that is not a uuid when the column or the cast is uuid. SQLSTATE 22P02 is invalid_text_representation. The message is invalid input syntax for type uuid: "" with the bad text in the quotes. Supabase returns that body on the failed request. PostgREST does not rewrite it into a PGRST code.
Generated clients send user.id before the session exists, so the value is undefined and the request contains the string undefined. A filter of .eq("id", "") or .eq("user_id", "null") is the same failure. auth.uid() is a uuid. A numeric id, a slug, or a Stripe cus_ id is not. Casting it in SQL does not make it one. A missing column is a different message. A duplicate primary key is 23505.
The next error you'll probably hit
Once this is fixed, the usual follow-up is Cannot coerce the result to a single JSON object. Cannot coerce the result to a single JSON object. PostgREST code PGRST116. .single() got zero rows or more than one. Read details before changing the query.
Prompt to paste back into your AI tool
Paste this above the error.
Postgres returns 22P02: invalid input syntax for type uuid: "<the quoted text>". The query or insert is: <paste> Do not cast the bad string to uuid. Do not send "undefined", "null", or an empty string. Do not change the primary key to text to accept a slug. Do not disable RLS. 1. Name the variable that became the quoted text. 2. If it is missing, skip the request until the session id exists. Use that uuid in the filter or insert. 3. If the value is a slug or another id on purpose, stop using it against the uuid column and say which column should hold it. 4. Change only that call.
Common questions
+The message is invalid input syntax for type uuid: "undefined". Where did undefined come from?
A missing JavaScript value was sent as the string undefined. The session or the route param was not there yet. Do not query with that string.
+auth.uid() works in the SQL editor and the client throws 22P02. Why?
The editor is not sending your filter value. The client is sending a non-uuid in a uuid parameter. Quote that parameter. The policy is not the line that failed.
Related errors
- Cannot coerce the result to a single JSON objectCannot coerce the result to a single JSON object. PostgREST code PGRST116. `.single()` got zero rows or more than one. Read `details` before changing the query.CursorLovableBoltSupabasePostgresOct 27, 2026
- duplicate key value violates unique constraintPostgres already has a row with this primary key or unique value. The SQLSTATE is 23505. PostgREST returns it as HTTP 409. Inserting the same profile or order again will keep failing.CursorLovableBoltSupabasePostgresOct 27, 2026
- null value in column violates not-null constraintnull value in column "user_id" of relation "todos" violates not-null constraint. Postgres 23502. The insert omitted a required column. Send it, or give the column a default. Do not drop NOT NULL to hide a missing value.CursorLovableBoltSupabasePostgresOct 27, 2026
- new row violates row-level security policynew row violates row-level security policy: RLS is on and no INSERT policy allows this role. Add a policy for the signed-in user. A missing GRANT differs.CursorLovableBoltSupabasePostgresOct 15, 2026