Supabase Error 406 "Not Acceptable" (PGRST116): Why .single() Fails and How to Fix It
A Supabase 406 almost always means .single() got zero rows or several. Why row-level security often causes it, and when to use .maybeSingle() or fix a policy.
A 406 "Not Acceptable" from Supabase's Data API almost always comes from .single(). It asks PostgREST, the server behind supabase.from(), for exactly one row as a JSON object, and when the query matches zero rows or more than one, PostgREST answers with HTTP 406 and error code PGRST116. Zero rows is the common case: the row doesn't exist yet, or row-level security hides it because the request isn't signed in or no policy matches that user. If "no row" is a normal outcome, use .maybeSingle(), which returns data: null with no error. If the row should be visible, fix the policy or the session. If several rows match, make the filter unique. Current PostgREST still uses 406 for this; only the wording of the message changed, in version 13.
Checked against the PostgREST docs (error reference, singular or plural responses) and changelog, the supabase-js single() reference, Supabase's row-level security guide and its PostgREST v14 changelog entry in November 2026, and reproduced with PostgREST 16.6, 14.1, 12.2.12 and 11.2.2 on PostgreSQL 18, queried with supabase-js 2.119.2 (@supabase/postgrest-js 2.119.2).
In the browser's Network tab, the request to /rest/v1/... shows status 406. In your code, supabase-js doesn't throw. It returns the error in the result:
{
data: null,
error: {
code: 'PGRST116',
details: 'The result contains 0 rows',
hint: null,
message: 'Cannot coerce the result to a single JSON object'
},
status: 406,
statusText: 'Not Acceptable'
}
On older PostgREST versions the message reads JSON object requested, multiple (or no) rows returned instead, with the same code and details.
What the 406 means
In HTTP, 406 means the server can't produce a response in the format the client asked for. That's literally what happens here. .single() sets this header on the request:
Accept: application/vnd.pgrst.object+json
That asks PostgREST for one JSON object instead of the usual array. PostgREST runs the query first, and if the result isn't exactly one row, there's no object it can honestly return. Its docs put it this way: "When a singular response is requested but no entries are found, the server responds with an error message and 406 Not Acceptable status code rather than the usual empty array and 200 status". The same applies to two or more rows.
You can reproduce it with curl against any PostgREST:
$ curl -i "http://localhost:3000/countries?id=eq.99" \
-H "Accept: application/vnd.pgrst.object+json"
HTTP/1.1 406 Not Acceptable
Content-Type: application/json; charset=utf-8
Proxy-Status: PostgREST; error=PGRST116
{"code":"PGRST116","details":"The result contains 0 rows","hint":null,"message":"Cannot coerce the result to a single JSON object"}
Without the Accept header, the same request returns 200 and [].
Which message you'll see
The status code has been 406 in every version we tried. The wording changed in PostgREST 13.0.0 (the changelog entry is "Clarify Accept: vnd.pgrst.object error message"):
| Where the error comes from | message |
details |
|---|---|---|
| PostgREST 11.2.2 and 12.2.12 | JSON object requested, multiple (or no) rows returned |
The result contains 0 rows |
| PostgREST 14.1 and 16.6 | Cannot coerce the result to a single JSON object |
The result contains 0 rows |
supabase-js .maybeSingle() with 2+ rows |
JSON object requested, multiple (or no) rows returned |
Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row |
The last row is built by supabase-js itself, not the server, which is why the old wording still turns up on current projects. Supabase started rolling out PostgREST v14 to new projects in December 2025, so which server message you get depends on your project's version. Either way, code is PGRST116, and details tells you how many rows matched. Read it first: 0 rows and 2 rows have different fixes.
Causes, most likely first
1. Row-level security hides the row. With RLS enabled, a SELECT only returns rows a policy allows, and rows it doesn't allow simply aren't in the result. There is no permission error: the result just has zero rows, which .single() turns into a 406. Supabase's RLS guide says that once RLS is on, no data is accessible through the API with the publishable key "until you create policies", and that a policy like auth.uid() = user_id will "silently fail for unauthenticated users" because auth.uid() is null for them.
In our test, the same profiles row gave three different results:
| Request | Result |
|---|---|
No session (anon role), .eq('id', 1).single() |
406, The result contains 0 rows |
| Signed in as the row's owner | 200, the row |
| Signed in as a different user | 406, The result contains 0 rows |
The usual reasons a user who thinks they're signed in gets 0 rows: the request carried no session, for example from a server-side client created without the user's auth cookies, so it ran as anon; the policy only covers anon or only authenticated; or the policy compares auth.uid() with the wrong column. Supabase Row-Level Security Explained covers how policies are evaluated.
2. The row doesn't exist (yet). A wrong ID, a deleted record, or a record that is created later than you expect. A typical case is loading a user's profiles row right after sign-up, before the trigger or the code that creates it has run, or for users who signed up before that trigger existed.
3. An update or delete with .select().single() matched nothing. If the update policy hides the row (or the filter is wrong), nothing is updated and nothing is returned. In our test, user A updating user B's profile with .update({ bio }).eq('id', 3).select().single() got the same 406 with The result contains 0 rows. The update didn't happen, and the 406 is the only sign of it.
4. The filter matches more than one row. .eq('user_id', userId).single() on a table where a user can have several rows fails with The result contains 2 rows. Filtering on a column that you assume is unique but isn't constrained as unique is the usual source.
How to find which one
Read
error.details.0 rowspoints to causes 1 to 3,N rowsto cause 4.Run the same query without
.single(). You get an array back:[]or several rows. That tells you whether the query itself is right.Check the session at the moment of the query:
const { data: { session } } = await supabase.auth.getSession() console.log('signed in as', session?.user.id ?? 'anon')Run the query as that user in SQL. In the SQL editor, a transaction can switch to the
authenticatedrole and set the JWT claims PostgREST would set, so RLS applies exactly as it does for the API:begin; set local role authenticated; set local request.jwt.claims = '{"sub":"<the user id>","role":"authenticated"}'; select * from profiles where id = 1; rollback;On our local copy this returned
(0 rows)for another user's ID and the row for its owner. If the row appears aspostgresbut not here, the policy is the cause.
Fix 1: use .maybeSingle() when "no row" is normal
.maybeSingle() accepts zero or one row:
const { data: profile, error } = await supabase
.from('profiles')
.select('*')
.eq('id', userId)
.maybeSingle()
if (error) throw error
if (!profile) {
// no profile yet: create one, or show onboarding
}
With zero rows we got data: null, error: null and status 200. With two or more rows it still returns the PGRST116 error and status 406, so it doesn't hide a non-unique filter.
It also works after writes. .update({ bio }).eq('id', id).select().maybeSingle() returned data: null with status 200 when nothing matched, which lets you tell "not updated" apart from a real error:
const { data, error } = await supabase
.from('profiles')
.update({ bio })
.eq('id', id)
.select()
.maybeSingle()
if (error) throw error
if (!data) {
// nothing updated: wrong id, or the update policy doesn't allow it
}
Fix 2: fix the policy or the session
If the row should be visible to this user, the policy has to allow it. A typical "users can read their own profile" policy:
create policy "read own profile"
on public.profiles for select
to authenticated
using ((select auth.uid()) = user_id);
Updates need their own for update policy. If the query runs on your server (a route handler, server component or API), make sure that Supabase client is built from the request's auth cookies or token. A client without them sends the request as anon, and RLS returns nothing.
Don't fix a 406 by disabling RLS or by querying with the service role key from the browser. Both make the error go away by making every row readable.
Fix 3: make the filter match one row
Filter on the primary key or on a column with a unique constraint. If several rows are expected and you want one of them, say which:
const { data } = await supabase
.from('orders')
.select('*')
.eq('user_id', userId)
.order('created_at', { ascending: false })
.limit(1)
.single()
With .limit(1) the query returns at most one row, so .single() only fails when there are none. If the column should be unique, add a unique constraint so the data can't drift.
Other 406s and nearby errors
PostgREST uses 406 for two more codes, both rare in normal supabase-js use. The rest of this table is what you may see instead of PGRST116 with the same queries:
| Status and code | Message | Meaning |
|---|---|---|
406 PGRST116 |
Cannot coerce the result to a single JSON object |
.single() matched 0 or 2+ rows |
406 PGRST106 |
(not reproduced) | You asked for a schema that isn't in the API's exposed schemas |
406 PGRST107 |
None of these media types are available: ... |
The Accept header asked for a format PostgREST can't produce |
404 PGRST205 |
Could not find the table 'public.profile' in the schema cache |
Wrong table name, or the table isn't exposed |
401 or 403 42501 |
new row violates row-level security policy for table "notes" |
An insert or update was blocked by RLS |
The PostgREST error reference maps 42501 to 403 for an authenticated request and 401 otherwise. Note the difference from PGRST116: RLS turns a blocked write into an error, but a hidden row on read is just absent. We also saw .insert(...).select().single() fail with 42501 rather than 406 when the table allowed inserts but had no select policy, because the returned row has to pass the select policy too.
If you prefer exceptions, .throwOnError() makes supabase-js throw a PostgrestError with the same code and message.
Quick checklist
- Read
error.details:0 rowsorN rows? - Run the query without
.single()and look at the array. - Check whether a session exists when the query runs.
- Test the query as the
authenticatedrole with that user's claims. - Zero rows is a normal outcome? Switch to
.maybeSingle(). - Row should be visible? Fix the select (or update) policy.
- Several rows? Filter on a unique column, or
.order()plus.limit(1).
EasySpawn doesn't run Supabase or PostgREST. If you keep Supabase as your backend, the fixes above are the ones that apply, wherever your frontend is hosted. If you move the data into the managed Postgres that comes with an EasySpawn server, your server-side code queries it directly, so .single() and its 406 are gone, but access rules then live in your own API code instead of RLS policies, and Claude Code, running on the same server, can write and test them against the real database. See how it works or join the waitlist.
Related: Supabase Row-Level Security Explained (for People Who Didn't Write the Policies) · What Is Supabase? A Beginner's Guide to the Backend Behind Many AI-Built Apps
Keep reading
Postgres "ERROR: permission denied for table": Causes and Fixes
Postgres "permission denied for table" means your role lacks a privilege on it. How to check grants, fix future tables with default privileges, and sequences.
pg_stat_statements: Find the Queries Slowing Down Your Postgres
pg_stat_statements records statistics for every distinct query your database runs — calls, total and mean time, rows, cache hits. How to enable it, the queries to find what costs the most, interpreting the results, resetting, and turning findings into indexes and fixes.