What it means
.single() tells the API “return exactly one row as an object, not an array”. If the query matches zero rows or more than one, the API refuses with PGRST116 and HTTP 406. The details field tells you which: The result contains 0 rows or The result contains 2 rows. Older versions said JSON object requested, multiple (or no) rows returned.
Zero rows: the usual causes
- The row really doesn't exist yet, for example a profile row that is created by a trigger after sign-up, or a settings row the user never saved.
- RLS hides it. Reads that fail a policy are not errors; the row is simply not returned. As
postgresin the SQL Editor you see it, as the user you don't. - An update or delete matched nothing.
.update({...}).eq('id', id).select().single()returns PGRST116 when the UPDATE policy'susingclause didn't match. Without.single()this fails silently: zero rows updated, no error. - The filter value is wrong: an id from another environment, a number sent as a string with spaces, or an
undefinedvariable. - Server code without the user's session. A route handler that creates its own client with only the publishable key runs as
anon, so “get my profile” matches nothing under RLS. The same query works in the browser, which is what makes this one confusing.
Two or more rows: the usual causes
- Filtering on a column that isn't unique (
emailwithout a unique constraint,slugper user but queried globally). - A missing filter, so the query returns everything the user can see.
.insert([a, b]).select().single(): inserting several rows and asking for one.
Fix: use maybeSingle() when “not found” is normal
const { data, error } = await supabase
.from('profiles')
.select('*')
.eq('id', userId)
.maybeSingle();
if (error) throw error; // a real problem, including more than one row
if (!data) {
// not found, or not visible to this user under RLS
}maybeSingle() returns data: null for zero rows. It still errors on two or more rows, which is what you want: that is a data bug, not an empty state.
Fix: make “one row” true in the database
If a column is supposed to identify one row, enforce it, so .single() can't see two:
alter table public.profiles add constraint profiles_username_key unique (username);When you really want “the latest one”, say so explicitly: .order('created_at', { ascending: false }).limit(1).maybeSingle().
Find out whether RLS is the reason
-- as the table owner: does the row exist?
select id, user_id from public.profiles where id = '<id>';
-- as the user: can they see it?
begin;
set local role authenticated;
select set_config('request.jwt.claims',
json_build_object('sub', '<user-uuid>', 'role', 'authenticated')::text, true);
select id from public.profiles where id = '<id>';
rollback;A row in the first query and none in the second means a policy is hiding it. Fix the policy or the ownership column, not the client code.
How to verify
The call returns an object (or null with maybeSingle()) and error is null. Then try an id that belongs to another user: you should get null, never their row.
Related guides
- Supabase auth.uid() returns null – where it works, where it can't, and how to test policies
- Supabase “duplicate key value violates unique constraint” on upsert – the five causes
- Supabase “new row violates row-level security policy” – causes and fix
- Supabase “must be owner of table objects” – what it means and what to run instead
More in Supabase RLS and Storage · all guides