Skip to content
VibeSafeDaily

Auth

Supabase .single() fails with "JSON object requested, multiple (or no) rows returned" (PGRST116)

Cataloged November 30, 2026 · Supabase

Symptom

This applies when a supabase-js .single() call fails with code PGRST116 and HTTP 406 Not Acceptable. If this project does not use supabase-js, this card does not apply. Supabase is the platform tag because the failure is that .single() call. The pages on this card describe .single() and row level security. They do not describe a bug in one generator, so the same failure happens on any app that uses supabase-js, including an app an AI coding tool generated. The same error is also seen in Lovable, Bolt, Cursor, and v0 apps that use supabase-js. This card does not say Lovable, Bolt, Cursor, or v0 write that call. A typical call is supabase.from('profiles').select('*').eq('id', userId).single(). It works with row level security off, fails once row level security is on, or works in the SQL editor and fails in the app. The error object for the older wording, which is still widely googled, is { code: 'PGRST116', details: 'The result contains 0 rows', message: 'JSON object requested, multiple (or no) rows returned' }, and that wording is HTTP 406 Not Acceptable. The current PostgREST message for the same code is "Cannot coerce the result to a single JSON object", with details "The result contains 0 rows" or N rows. The PostgREST errors page lists PGRST116 as 406, "More than 1 or no items where returned when requesting a singular response". The resource representation docs say a singular response with no entries is 406 and code PGRST116, and they print "Cannot coerce the result to a single JSON object" with details "The result contains 0 rows". The PostgREST source sets the SingularityError message to "Cannot coerce the result to a single JSON object". The supabase-js single page says: "Query result must be one row (e.g. using .limit(1)), otherwise this returns an error." Supabase's PostgREST error codes page lists PGRST116 as 406. Stack Overflow question 72654424 shows that older message and "Results contain 0 rows" after enabling row level security. Its accepted resolution is that the server-side request did not carry the user's JWT. The longer guide linked from this page is "Lovable Supabase data exposed: check RLS on your own app".

Root cause

.single() asks for exactly one row, and zero rows or two or more rows returns an error. The supabase-js single page says the query result must be one row (for example using .limit(1)), otherwise this returns an error. The PostgREST resource representation docs say a singular response with no entries is 406 and code PGRST116. The errors page lists PGRST116 as 406, "More than 1 or no items where returned when requesting a singular response". Zero rows often means row level security hid the row. Supabase's row level security guide says a USING clause that filters a row out "raises nothing, matches zero rows", so .single() reports 0 rows. The SQL editor runs as a privileged role, so the row shows there and the same read fails in the app. Zero rows also happen when the request has no user session. That request runs as anon, and auth.uid() is null. One case is a server-side client created without the user's cookies or JWT. The fix is to attach the user session to the client that makes the call. A server client uses the request's cookies, and auth.getUser() returns a user before the query. Stack Overflow 72654424's accepted resolution is that the server-side requests were not sending the JWT. Zero rows also happen when the row genuinely does not exist yet, such as a profile that has not been created. The repair for that case is .maybeSingle(), which is for zero or one row, and handling null. The maybeSingle page says: "Query result must be zero or one row ... otherwise this returns an error." Swapping .single() for .maybeSingle() when the row should be visible silences a row level security or session bug. Two or more rows means the filter column is not unique, for example a lookup by email with no unique constraint. The repair is a unique constraint, or a filter on the primary key. .limit(1) just picks one row arbitrarily. A call shaped .update(...).select().single() also needs a SELECT policy. The row level security guide says: "To perform an UPDATE operation, a corresponding SELECT policy is required." The catalog card "Supabase update says success but nothing changes, and the quick fix opens every row" is that case. Disabling row level security, a policy of using (true), a policy for anon, or moving the call to the service_role or secret key makes the error go away by letting every user read every row.

Before and after

The before line is the typical call supabase.from('profiles').select('*').eq('id', userId).single(). It works with row level security off, fails once row level security is on, or works in the SQL editor and fails in the app. The older error is code PGRST116, details "The result contains 0 rows", message "JSON object requested, multiple (or no) rows returned", HTTP 406 Not Acceptable. The current PostgREST message for the same code is "Cannot coerce the result to a single JSON object". The after lines are the SELECT policy for the signed-in owner: to authenticated using ((select auth.uid()) = <owner column>). Use the owner column the table already stores. Supabase's row level security guide says a USING clause that filters a row out raises nothing and matches zero rows, and that an UPDATE needs a corresponding SELECT policy. This pair does not disable row level security, does not use using (true), does not add a policy for anon, and does not move the call to the service_role or secret key. If the row may legitimately not exist, the repair is .maybeSingle() and null handling. If the result is two or more rows, add a unique constraint or filter by the primary key. .limit(1) just picks one row arbitrarily.

Before

supabase.from('profiles').select('*').eq('id', userId).single()

After

to authenticated
using ((select auth.uid()) = <owner column>)

Fix prompt

In this project only, find every supabase-js .single() call and repair the zero-row or many-row result without opening the table. Do not open a Supabase project you do not own. Do not print keys, tokens, cookies, or row data. Do not disable row level security. Do not write using (true). Do not add a policy for anon. Do not move the call onto the service_role or secret key. Do not send a request to a project this one does not own.

1. This prompt applies if this project uses supabase-js and a .single() call fails with code PGRST116. The older message, still widely googled, is "JSON object requested, multiple (or no) rows returned", with details "The result contains 0 rows", and that wording is HTTP 406 Not Acceptable. The current PostgREST message for the same code is "Cannot coerce the result to a single JSON object", with details "The result contains 0 rows" or N rows. The PostgREST errors page lists PGRST116 as 406, "More than 1 or no items where returned when requesting a singular response". The supabase-js single page says: "Query result must be one row (e.g. using .limit(1)), otherwise this returns an error." If this project does not use supabase-js, say so and stop. The failure is this project's .single() call. It is not a bug in the tool that generated the app. The same failure happens on any app that uses supabase-js, including an app an AI coding tool generated.

2. Find every .single() call. Give the file and the line. A typical call is supabase.from('profiles').select('*').eq('id', userId).single(). That call works with row level security off, fails once row level security is on, or works in the SQL editor and fails in the app. For each call, log error.code and error.details. Do not log row contents. Decide whether the details are 0 rows or 2 or more rows. The resource representation docs say a singular response with no entries is 406 and code PGRST116, and they print details "The result contains 0 rows". Details can also be N rows.

3. In the SQL editor of this project, list policies with no row data. Run: select tablename, roles, cmd, policyname, qual, with_check from pg_policies where schemaname='public'; Show me that result. Do not print rows from the tables the app reads.

4. For a 0-row result, check three things before you change the call. (a) The client that runs the query has the user's session. A server-side client uses the request's cookies. auth.getUser() returns a user before the query. A request with no session runs as anon, and auth.uid() is null. Stack Overflow 72654424 shows the older message and "Results contain 0 rows" after enabling row level security, and its accepted resolution is that the server-side request did not carry the user's JWT. (b) The table has a SELECT policy for the signed-in owner, shaped to authenticated using ((select auth.uid()) = <owner column>). Use the owner column this table already stores. Do not invent a column. Supabase's row level security guide says a USING clause that filters a row out "raises nothing, matches zero rows", so .single() reports 0 rows. The SQL editor runs as a privileged role, so a row that shows there can still be 0 rows in the app. (c) The row may legitimately not exist yet, such as a profile that has not been created. Only in that case, change .single() to .maybeSingle() and handle null. The maybeSingle page says: "Query result must be zero or one row ... otherwise this returns an error."

5. Do not replace .single() with .maybeSingle() when the row should be visible. That swap silences a row level security or session bug. Fix the session or the SELECT policy instead.

6. For 2 or more rows, the filter column is not unique. A lookup by email with no unique constraint is one case. Add a unique constraint on that column, or filter by the primary key. Do not use .limit(1) as the repair. .limit(1) just picks one row arbitrarily.

7. If the call is .update(...).select().single(), add the SELECT policy from step 4 when it is missing. The row level security guide says: "To perform an UPDATE operation, a corresponding SELECT policy is required." The catalog card "Supabase update says success but nothing changes, and the quick fix opens every row" is that case.

8. Do not make the error go away by disabling row level security, by writing using (true), by adding a policy for anon, or by moving the call to the service_role or secret key. Those let every user read every row. Leave the secret key out of browser code.

9. Show me the call diff and the policy diff. Do not print keys, tokens, cookies, or row data. Do not edit unrelated files.

Paste this into the coding tool that has your own project open.

2-minute self-check

These steps are for an app you own. Do not run them against someone else's project.

  1. In an app you own, sign in as test user A and load the page that calls .single(). The page loads, and the call does not return PGRST116. Do not run this in an app you do not own.
  2. In the SQL editor of that same project, run select tablename, roles, cmd, policyname, qual, with_check from pg_policies where schemaname='public'; Every table that .single() reads has a select policy scoped to the owner. None of those policies are using (true). None of them are for anon. Do not run this in a project you do not own.
  3. Still in an app you own, sign in as test user B and request user A's row id through the same .single() call. The result should be PGRST116, or null for 0 rows, and it should not be A's data. Do not request a row in a project you do not own.

Common questions

Disabling row level security, using (true), a policy for anon, or the service role key made the error stop. Should I leave that?

No. Those changes make the error go away by letting every user read every row. .single() asks for exactly one row, and zero rows is often row level security hiding the row or a request that has no user session. Supabase's row level security guide says a USING clause that filters a row out raises nothing and matches zero rows. The repair is a SELECT policy for the signed-in owner, to authenticated using ((select auth.uid()) = <owner column>), or attaching the user's session to the client that queries. The longer guide on this page, Lovable Supabase data exposed, is the check for a table left open.

Replacing .single() with .maybeSingle() stopped the error. The row should be there. Is that the repair?

No. Swapping .single() for .maybeSingle() when the row should be visible silences a row level security or session bug. Use .maybeSingle() when the row may legitimately not exist yet, such as a profile that has not been created, and handle null. The maybeSingle page says: "Query result must be zero or one row ... otherwise this returns an error." Two or more rows is a different case. The filter column is not unique, for example a lookup by email with no unique constraint. Add a unique constraint or filter by the primary key. .limit(1) just picks one row arbitrarily.

The row shows in the SQL editor, and the app returns PGRST116. Does .update().select().single() need something else?

The SQL editor runs as a privileged role, so the row can show there while the app gets 0 rows. A request with no user session runs as anon, and auth.uid() is null. A server-side client created without the user's cookies or JWT is one case. Stack Overflow 72654424 shows the older message and "Results contain 0 rows" after enabling row level security, and its accepted resolution is that the server-side request did not carry the user's JWT. A call shaped .update().select().single() also needs a SELECT policy. The row level security guide says: "To perform an UPDATE operation, a corresponding SELECT policy is required." The catalog card "Supabase update says success but nothing changes, and the quick fix opens every row" is that case.

Longer guide

Sources

Same symptom

Same platform