Supabase error PGRST116 (Multiple or Zero Rows for a Singular Request) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Use .maybeSingle() when 0-or-1 rows are expected. If that does not apply, add a unique filter such as .eq('id', value) before .single() — the full checklist is below.
Error code: PGRST116
Official name: Multiple or Zero Rows for a Singular Request
Service: Supabase
More than 1 or no items were returned when requesting a singular response.
const { data, error } = await supabase
.from('profiles')
.select('*')
.eq('user_id', userId)
.maybeSingle()
if (data === null) {
// no profile yet - treat as a fresh user
return createDefaultProfile(userId)
}
maybeSingle returns null for 0 rows and never raises PGRST116 for the empty case.
const { data, error } = await supabase
.from('orders')
.select('*')
.eq('id', orderId)
.single()
if (error?.code === 'PGRST116') {
return notFound('Order does not exist')
}
When you must use .single(), guard the 406 so a missing row maps to a 404 response.
Replace .single() with .maybeSingle() for optional rows; the result is null instead of a PGRST116 error.
const { data } = await supabase
.from('profiles')
.select('*')
.eq('user_id', userId)
.maybeSingle() // null when no row matches
The Python client surfaces the same PostgREST code; use maybe_single() for optional rows.
row = (
supabase.table('profiles')
.select('*')
.eq('user_id', user_id)
.maybe_single()
.execute()
).data # None when no row matches
Most often this happens when .single() called when the query returns 0 rows, or when query matched multiple rows while using .single().
Use .maybeSingle() when 0-or-1 rows are expected.
This page documents fixes for: supabase-js, supabase-python.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official Supabase documentation linked below and adds practical troubleshooting guidance on top.