Short answer
You asked for exactly one row with .single(), and the query found zero rows or more than one. Older PostgREST versions, and .maybeSingle() with two rows, word it as JSON object requested, multiple (or no) rows returned. The usual causes: row level security hides the row from this user, the row was never created, there are duplicates, or an update matched nothing. Use .maybeSingle() where a missing row is normal, fix the select policy, and add a unique constraint. Never remove the policy to make .single() work.
Ask an AI about this page:ChatGPTClaude
On this page
.single() tells PostgREST, the API in front of your Supabase database, that you expect exactly one row. When the query finds zero rows or two or more, PostgREST refuses with HTTP 406 and code PGRST116. The details field tells you which case you hit: The result contains 0 rows or The result contains 2 rows. Older versions say JSON object requested, multiple (or no) rows returned instead. Same error, same fixes.
The error usually looks like this in the browser console:
{
"code": "PGRST116",
"details": "The result contains 0 rows",
"hint": null,
"message": "Cannot coerce the result to a single JSON object"
}Find your cause in 30 seconds
| What you see | Most likely cause |
|---|---|
0 rows, but the row is in the table editor | RLS hides the row |
0 rows for new users only | The row does not exist yet |
2 rows or more | There are duplicates |
0 rows after .update(...).select().single() | The update matched no row |
We reproduced every cause on Postgres with Supabase’s roles before writing this page, using a profiles table with one row per user:
create table public.profiles (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users (id) on delete cascade,
display_name text,
created_at timestamptz not null default now()
);
alter table public.profiles enable row level security;And this is the query your AI builder most likely wrote:
const { data, error } = await supabase
.from("profiles")
.select("id, display_name")
.eq("user_id", user.id)
.single();The four causes
1. RLS hides the row
With row level security on, a user only sees rows that a select policy allows. No select policy, or one that checks the wrong column, means 0 rows. The row exists, the table editor shows it, and your app still gets PGRST116. We checked this: the same select returns 1 row as the owner and 0 rows as the signed-in user. A request without a session runs as anon and gets 0 rows for the same reason.
2. The row does not exist yet
The profile is created somewhere else, for example on the onboarding page, and the first query runs before that. Or the sign-up flow that should create it failed once. For that user there is simply no row, and .single() reports it as an error.
3. There are duplicates
Nothing in the table stops two profiles for the same user. A double click, a retried request or a “create the profile if it is missing” check that ran twice is enough. Then the query finds 2 rows and .single() fails. .maybeSingle() fails too: supabase-js turns two rows into a PGRST116 error with the older message.
4. The update matched no row
.update(...).eq("id", id).select().single() returns the changed row. If the update matched nothing, because there is no update policy for this user or the filter is wrong, the update changes 0 rows without an error, and .single() turns that into PGRST116. The data was not saved. Check the update policy, not the select.
How to fix it
First, find out which case you have. Run this in the SQL Editor. It runs as the owner, so it sees every row:
select u.id, u.email, count(p.id) as profiles
from auth.users u
left join public.profiles p on p.user_id = u.id
group by u.id, u.email
having count(p.id) <> 1;If it returns nothing, every user has exactly one profile, and the problem is the policy (cause 1 or 4). Then fix the table so each case cannot come back. This removes duplicates (it keeps the newest), adds a unique constraint, and gives users a select and an update policy for their own row only:
delete from public.profiles a
using public.profiles b
where a.user_id = b.user_id
and (a.created_at, a.id) < (b.created_at, b.id);
alter table public.profiles
add constraint profiles_user_id_key unique (user_id);
create policy "Users can read their profile"
on public.profiles for select
to authenticated
using ((select auth.uid()) = user_id);
create policy "Users can update their profile"
on public.profiles for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);The delete removes data, so look at the duplicates first and keep a backup. With the unique constraint, a second profile for the same user fails with a duplicate key error instead of creating a silent duplicate.
Where no row is a normal answer, use .maybeSingle() and handle null:
const { data: profile, error } = await supabase
.from("profiles")
.select("id, display_name")
.eq("user_id", user.id)
.maybeSingle();
if (error) throw error;
if (!profile) {
// no profile yet: show onboarding or create it
}Do not swap .single() for .maybeSingle() to hide cause 1 or 4. The error then disappears, but the user still sees nothing or the update still did not save.
My Supabase app fails with PGRST116 “Cannot coerce the result to a single JSON object” (or “JSON object requested, multiple (or no) rows returned”) on a query that uses .single(). Find the query and the table’s policies in the migrations. Tell me from the details field whether the query found 0 rows or more than one. Then fix it like this, in a new migration: make sure there is a select policy for the authenticated role that allows the row only when (select auth.uid()) equals the owner column, and an update policy with the same check in USING and WITH CHECK if the code updates the row. If the table should hold one row per user, add a unique constraint on the owner column after showing me the duplicates. In the app code, use .maybeSingle() only where a missing row is normal, and handle null there.
Do not disable RLS, do not add policies with true, do not use the service role key in client code and do not edit existing migrations. Show me the migration and the code change before applying them.
Check that the fix works
In the SQL Editor, act as the signed-in user inside a transaction. Use a real user id from Authentication → Users:
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "11111111-1111-1111-1111-111111111111", "role": "authenticated"}';
select id, display_name from public.profiles
where user_id = '11111111-1111-1111-1111-111111111111';
rollback;It must return exactly one row. Then keep the same sub and change only the where to another user’s id: it must return no rows. That empty result is the policy protecting the other user, and .single() on someone else’s profile should keep failing. If you see empty results without an error elsewhere, read why a Supabase query returns an empty array. The guide to testing RLS policies has the full set of checks to run before launch.
Frequently asked questions
Is “JSON object requested, multiple (or no) rows returned” the same error?
Yes. It is the older wording of PGRST116, used by PostgREST 12 and earlier. supabase-js still uses it when .maybeSingle() gets more than one row. Newer PostgREST says Cannot coerce the result to a single JSON object, with details such as The result contains 0 rows. The causes and fixes are the same.
Should I switch to .maybeSingle() everywhere?
Only where no row is a normal answer, for example a profile that may not exist yet. Then data is null and error is null, and your code must handle null. If the row should always be there, keep .single(): the error tells you something is wrong, usually a policy or a missing row.
The row is in the table editor. Why does my app get 0 rows?
The table editor runs as the database owner, and row level security does not apply to the owner. Your app runs as the anon or authenticated role, so the select policies decide which rows it sees. If no policy lets this user see the row, the query finds 0 rows and .single() fails.
Can I fix it by making the select policy using (true)?
No. That makes every row of the table readable with your public anon key, which ships in every browser bundle. The error goes away because now everyone sees everything. Write a policy that lets the user see their own row instead.
Sources
- 1.PostgREST Error Codes — Supabase Docs
- 2.Errors — PostgREST Documentation
- 3.JavaScript: Retrieve one row of data — Supabase Docs
- 4.JavaScript: Retrieve zero or one row of data — Supabase Docs
- 5.Row Level Security — Supabase Docs