Fix guide · updated 2026-11-13
Supabase 406 and PGRST116: "Cannot coerce the result to a single JSON object"
406 (Not Acceptable) · PGRST116 · Cannot coerce the result to a single JSON object · JSON object requested, multiple (or no) rows returned
Your page stays empty, and the browser console shows 406 (Not Acceptable) on a request to /rest/v1/, with PGRST116 in the answer. Supabase isn't down. Your code asked for exactly one row with .single(), and the query found zero, or more than one. The error tells you which. Here's how to read it and fix the real cause.
What the error says
The full answer from Supabase looks like this:
{"code": "PGRST116",
"details": "The result contains 0 rows",
"hint": null,
"message": "Cannot coerce the result to a single JSON object"}
You may also see the older wording JSON object requested, multiple (or no) rows returned, with details like Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row. It's the same error. In current supabase-js, that second form comes from .maybeSingle() when it finds more than one row. We checked both wordings in the source code of PostgREST 16.5 (the API server behind Supabase's /rest/v1/) and of @supabase/postgrest-js 2.119.0, the query library inside supabase-js.
Read the details line first
contains 0 rows: the row doesn't exist, or this user isn't allowed to see it. Causes 1 to 3 below.contains 2 rows(or more): duplicates, or a filter that matches too much. Cause 4.
To see the request, open the browser's Network tab and click the red 406 line. Its URL shows the table and the filter, for example /rest/v1/profiles?select=*&id=eq.6f1c….
Cause 1: the row doesn't exist yet
The classic case: the app loads the user's profiles row right after sign-up, but nothing created that row. Two fixes, and you usually want both:
- Create the row when the user signs up, with a trigger on
auth.users. If that trigger breaks sign-up, see Database error saving new user. - Use
.maybeSingle()where "no row yet" is a normal state. It returnsnullinstead of an error.
const { data: profile, error } = await supabase
.from('profiles')
.select('*')
.eq('id', user.id)
.maybeSingle(); // null when there's no row, instead of a 406
if (error) throw error;
if (!profile) {
// first visit: create the profile or show onboarding
}
Cause 2: row-level security hides the row
With RLS on, a row that no policy lets this user read is invisible. Postgres doesn't raise an error: the query just returns 0 rows, and .single() turns that into the 406. To check, run the same query in the SQL Editor. It runs as postgres, which RLS doesn't limit on your own tables, so if the row shows up there, a policy is hiding it from your app. Add a read policy, for example:
create policy "read own profile" on public.profiles
for select to authenticated
using ((select auth.uid()) = id);
Two variants of the same cause:
- The page is open to signed-out visitors. A policy written
to authenticateddoesn't cover them, so a public page (a shared profile, a product page) gets 0 rows. If strangers may see that row, add a policy foranontoo, limited to the rows that are meant to be public. - The answer isn't a 406 at all.
permission denied for tablemeans the table has no grant: see this guide. Policy errors on writes are covered in new row violates row-level security policy.
Cause 3: the filter points at the wrong column
AI-written code often filters on id while the table stores the user in user_id, or the reverse. .eq('id', user.id) then matches nothing. Open the table in the Table Editor, find the column that holds the user's id, and filter on that one.
Updates hit this too. .update({ ... }).eq('id', x).select().single() answers 406 when the update matched 0 rows: the filter found nothing, or no update policy allows it. Nothing was saved.
Cause 4: more than one row
When the details say contains 2 rows, the filter matched several rows: two profile rows for one user (the trigger and the app both inserted one), or a filter on a column that isn't unique, like email. .maybeSingle() won't help here: with more than one row it returns the same PGRST116 error. Find the duplicates, clean them up, then make them impossible:
-- which users have more than one row?
select user_id, count(*) from public.profiles
group by user_id having count(*) > 1;
-- after removing the extra rows
alter table public.profiles
add constraint profiles_user_id_key unique (user_id);
If you really want one row out of several, say so in the query. With a created_at column, .order('created_at', { ascending: false }).limit(1).maybeSingle() returns the newest one.
.single() or .maybeSingle()?
.single(): exactly one row must exist. Zero or several is an error (406). Use it when a missing row means a real bug..maybeSingle(): zero rows is fine (dataisnull). Several is still an error.- Neither: you get a list, which can be empty.
Switching to .maybeSingle() silences causes 1 to 3, but it only really fixes cause 1. If RLS or a wrong filter hides the row, your users still see an empty page.
If an AI tool wrote the query
AI builders like Lovable, Bolt and Cursor often reach for .single(). Tell the AI once, in its project instructions or your next prompt:
Use .maybeSingle() when a row may not exist yet (profiles, settings) and handle data === null. Keep .single() only where exactly one row must exist. Filter on the column that stores the user's id. Add a unique constraint on any column that must hold one row per user.
Still stuck?
Copy the failing request's filter from the Network tab and run the same filter in the SQL Editor. If the row is there but not in the app, it's RLS. If there's no row anywhere, it was never created. Two or more rows means duplicates. Supabase documents both methods in its JavaScript reference, single() and maybeSingle(), and PostgREST lists its error codes in its error reference.
Other Supabase problems? See Supabase fixes.