Fix Supabase "Cannot coerce the result to a single JSON object" (PGRST116)
Your app calls Supabase, and instead of data the console shows this: { "code": "PGRST116", "message": "Cannot coerce the result to a single JSON object", "details": "The result contains 0 rows", "hint": null }
Your app calls Supabase, and instead of data the console shows this:
{
"code": "PGRST116",
"message": "Cannot coerce the result to a single JSON object",
"details": "The result contains 0 rows",
"hint": null
}
Older projects and older libraries print the same error as JSON object requested, multiple (or no) rows returned. The HTTP status is 406 Not Acceptable, which looks alarming and points people at headers, CORS or the wrong API key. It is none of those. It is a row-count problem, and it appears all the time in Lovable, Bolt and Vite apps that load "the current user's profile" with .single().
Below is how I read the error, the four causes I check in order, and what to change. It's based on the PostgREST singular-or-plural docs, the PostgREST error reference, the Supabase Row Level Security guide, the supabase-js maybeSingle reference and the postgrest-js source, all read on 16 November 2026.
What the error means
Supabase's data API is PostgREST. By default it returns every result as an array, even when there is one item. .single() in supabase-js asks for something different: it sets the Accept: application/vnd.pgrst.object+json header, which tells PostgREST to return one object. The PostgREST docs say that when a singular response is requested "but no entries are found", the server answers with a 406 Not Acceptable and an error body instead of an empty array. The error reference lists PGRST116 as "More than 1 or no items where returned when requesting a singular response."
So the error means one thing: .single() got zero rows or more than one row. Nothing is wrong with your key, your headers or your network. The details field tells you which: The result contains 0 rows or a message with the actual count, such as The result contains 2 rows.
The wording of message changed in PostgREST in November 2024 (PostgREST #3795), which is why you see two versions. Match on error.code === 'PGRST116', not on the message text.
Step 1: take .single() off and look
Before changing any policy, remove .single() from the failing query and log what comes back:
const { data, error } = await supabase
.from('profiles')
.select('*')
.eq('id', user.id)
console.log(data, error)
Now it's [] with no error, or an array with more than one item. That one test splits the problem in two. Empty array: causes 1 to 3. Several items: cause 4.
Cause 1: the row really isn't there
The simplest case is a row that doesn't exist yet. A user signs up, your app immediately loads their profile, and nothing has created it. This is plain logic, not a Supabase bug: zero rows with .single() is an error by design.
If "no row" is a normal answer, say so with .maybeSingle(). The supabase-js reference describes it as: "Query result must be zero or one row (e.g. using .limit(1)), otherwise this returns an error." With zero rows you get data: null and no error:
const { data: profile, error } = await supabase
.from('profiles')
.select('*')
.eq('id', user.id)
.maybeSingle()
if (error) throw error
if (!profile) {
// first visit: create it, or show onboarding
}
Keep .single() for the case where a missing row is a genuine bug you want to hear about.
Cause 2: Row Level Security hides the row
This is the one that confuses people most, because the row exists and the app still can't see it. RLS doesn't return an error for a row you aren't allowed to read. It filters the row out, so to your query it looks like it doesn't exist, and .single() turns that into PGRST116. The RLS guide's own test example expects exactly this: it asserts that another user "reads no profiles".
Two things to check:
-
Is there a
selectpolicy that matches the user you query as? A policy that doesn't match leaves the row out of the result. -
Is the user signed in? The Supabase RLS guide notes that when a request has no authenticated user,
auth.uid()returnsnull, and a policy such asusing (auth.uid() = user_id)"will silently fail for unauthenticated users", becausenull = user_idis never true. A session that expired, or a query that runs before sign-in has finished, gives exactly this.
A scoped read policy looks like this:
create policy "Users can read their own profile"
on public.profiles for select
to authenticated
using ( (select auth.uid()) = id );
Don't fix the error with using (true). That makes the whole table readable to everyone the policy covers. If you want the wider picture of what RLS errors look like, I've written about the write side separately (link at the end).
Cause 3: an update or delete matched nothing
.update(...).select().single() and .insert(...).select().single() fail the same way when the returned rows are zero. For an update, either the filter matched nothing, or RLS stopped it. The RLS guide is direct about one trap: "To perform an UPDATE operation, a corresponding SELECT policy is required. Without a SELECT policy, the UPDATE operation will not work as expected."
This also shows up in the wild. A reader in postgrest-js issue #431, "Updating row returns error code PGRST116" (still open when I checked), reports fixing the same update error by updating the policies. One commenter there found a different cause, a computed field in the select that returned null, so if your policies are right, look at what you select.
Test it the same way: drop .single() and check whether data is [].
Cause 4: more than one row matched
If the unfiltered query returns several items, your filter isn't unique. .eq('email', email) on a table without a unique constraint, a missing .eq('user_id', ...), or a join that multiplies rows will all do it. .single() is not a filter and doesn't pick the first row for you.
Decide what you mean:
- One row per user: add a unique constraint or filter on the primary key.
- Latest of many:
.order('created_at', { ascending: false }).limit(1).maybeSingle().
The supabase-js reference itself uses .limit(1) in its .single() example for this reason.
One caution for writes. A supabase-js issue opened on 7 November 2026, supabase-js #2834, reports that .delete() or .update() with .select().maybeSingle() that matches two rows returns PGRST116 while the change is already committed, and that .single() on the same request is rejected by PostgREST instead. At the time of writing the issue is open, so treat it as a report, not settled behavior. The practical rule doesn't depend on it: filter updates and deletes by primary key, and don't use .single() or .maybeSingle() as a safety check on how many rows a write will touch.
Which method to use
| Situation | Use |
|---|---|
| The row must exist, a missing row is a bug |
.single() and handle the error |
| The row may not exist yet |
.maybeSingle() and check for null
|
| You expect a list | neither: use the array |
| Several rows could match | make the filter unique, or order and .limit(1)
|
And in every case, check error before you read data. It's easy to write const { data } = await ... and throw the error away, and then the app shows an empty screen instead of the real message.
Prove it works
- Sign in as a normal test user, not as the project owner, and run the query again.
- Sign out and run it: you should get a clean "not signed in" path, not a thrown
PGRST116. - Test with a brand-new user who has no row yet.
- Test with two users and confirm each one sees only their own row.
If all four behave, the fix is done. If step 4 shows one user seeing another's data, stop and fix the policy before anything else.
If your write fails with new row violates row-level security policy instead, that's a different error with a different fix, and I covered it here: Supabase "new row violates row-level security policy". If you'd like a second pair of eyes on a whole app, the free AI app audit reports findings with the file and line.
I wrote this with AI assistance and reviewed it myself.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.