Supabase SELECT returns empty rows: RLS diagnostic guide
Diagnose Supabase queries that return zero rows despite matching rows: check RLS status, policies, JWT claims, and service_role bypass.
11 Sept 2026, 11:45 UTC

Problem: SELECT returns an empty array although matching rows exist
You query a Supabase table from a browser or mobile client and get [], even though you can see rows in the Table Editor. The useful takeaway is that this is usually an authorization problem, not a missing row problem: row level security (RLS) is likely enabled, but no policy grants the client’s role permission to read those rows.
Row level security is a Postgres feature that adds a policy check to every row a query touches. Supabase exposes three database roles relevant here: anon for unauthenticated clients, authenticated for logged-in clients, and service_role for trusted server-side code. service_role bypasses RLS entirely. auth.uid() is a Supabase helper that returns the user ID from the current JWT, usually the sub claim.
Cause and diagnostic table
| Observation | Likely cause | First check |
|---|---|---|
Client SELECT returns []; Table Editor shows rows | RLS enabled, no SELECT policy for anon or authenticated | Query pg_class and pg_policies |
| Rows appear after sign-in but not before | Policy exists for authenticated but not anon, or JWT claims are missing | Compare unauthenticated and authenticated client requests |
service_role returns rows; client keys return [] | RLS policy is filtering client requests; connectivity is fine | Run the same SELECT with a service_role client |
| Policy exists but still no rows | USING clause references the wrong column, table, or stale auth.uid() claim | Inspect JWT claims and policy expression side by side |
Ordered checks
Check 1: Confirm RLS is enabled
Run this in the Supabase Dashboard SQL Editor or in psql connected to your project. You need table owner or superuser permissions; the anon client role cannot run it.
SELECT relrowsecurity
FROM pg_class
WHERE relname = 'your_table';
Expected check: t means RLS is enabled; f means it is not. Risk: enabling RLS on a table with no policies blocks all non-superuser access immediately, including the anon role used by unauthenticated clients.
Check 2: List policies for the table and role
SELECT policyname, roles, cmd, qual
FROM pg_policies
WHERE tablename = 'your_table';
Look for a row where cmd is SELECT and roles includes the role your client uses. The qual column is the USING expression that filters rows. If no matching row exists, the client is authorized to see nothing. Note that the SQL Editor usually runs as the postgres superuser, so a successful query there does not prove that a client can read the row.
Check 3: Compare service_role with client keys
Run the same SELECT in two clients: one with your public anon key and one with service_role only in server-side code.
// Client-side: anon or authenticated key
const { data, error } = await supabase
.from('your_table')
.select('*');
// Server-side only: never embed this key in a browser or mobile app
const serviceClient = createClient(supabaseUrl, serviceRoleKey);
const { data: serviceData } = await serviceClient
.from('your_table')
.select('*');
Expected check: if serviceData has rows but data is empty, the problem is RLS policy evaluation, not network connectivity or missing rows. Risk: never hardcode service_role in client-side code; it bypasses RLS and can read or modify every row.
Check 4: Verify JWT claims against policy expressions
Policies that use auth.uid() depend on the JWT sent with the request. If the token is missing, expired, or lacks the expected user ID, auth.uid() evaluates to null and the policy can filter out every row.
Inspect the signed-in user on the client:
const { data: { user } } = await supabase.auth.getUser();
console.log(user?.id);
Compare that ID with the column referenced in the policy, for example id = auth.uid(). If the user signed in recently but the client still holds an old session, sign out and back in or refresh the session so claims are current.
Check 5: Confirm the policy expression references the correct column
A policy can exist and still return zero rows if its USING clause points at the wrong column or relationship.
-- Example: rows belong to the user who owns them
CREATE POLICY "Users read own profiles"
ON profiles
FOR SELECT
TO authenticated
USING (owner_id = auth.uid());
If your table stores the user ID in user_id instead of owner_id, the expression above filters out every row. Fix the column name, not the RLS setting.
Fixes tied to findings
Missing SELECT policy
Create the policy before enabling RLS, or enable RLS and add the policy in the same transaction, so there is no window where non-superusers are locked out.
-- Allow signed-in users to read their own rows
CREATE POLICY "Users read own rows"
ON your_table
FOR SELECT
TO authenticated
USING (user_id = auth.uid());
-- Allow public read of published rows
CREATE POLICY "Anyone reads published rows"
ON your_table
FOR SELECT
TO anon, authenticated
USING (is_published = true);
ALTER TABLE your_table ENABLE ROW LEVEL SECURITY;
If RLS is already enabled, run only the CREATE POLICY statements. Policy changes apply to new transactions; long-lived client sessions or prepared statements may still use old authorization decisions until they are recreated.
Wrong policy expression
Drop and recreate the policy with the correct column:
DROP POLICY IF EXISTS "Users read own rows" ON your_table;
CREATE POLICY "Users read own rows"
ON your_table
FOR SELECT
TO authenticated
USING (user_id = auth.uid());
Stale or missing JWT
No database change fixes a missing token. Ensure the client sends the session header, handle expired tokens, and refresh the session before retrying the query.
Service_role misuse
Use service_role only in server-side functions or backend routes. For client reads, rely on anon or authenticated with a correct SELECT policy.
Limitations
- Table owners bypass RLS unless you run
ALTER TABLE your_table FORCE ROW LEVEL SECURITY. Testing as the table owner can hide policy failures. pg_policiesshows the policy text, not the runtime evaluation result.- RLS does not replace column-level privileges or database grants.
- Behavior can vary by Supabase plan and Postgres version; verify against your own project.
Practical verification after a fix
Retry the request with the exact client key your app uses. Confirm the response contains the expected rows and that unauthenticated clients still cannot read rows they should not see. Do not consider a SQL Editor result sufficient, because it typically runs as a superuser and bypasses RLS.
Rollback for test-only changes
If you enabled RLS or created a policy only to test in a non-production project, revert with:
DROP POLICY IF EXISTS "Users read own rows" ON your_table;
ALTER TABLE your_table DISABLE ROW LEVEL SECURITY;
Do not disable RLS in production to bypass debugging; it exposes every row to every database role.
Escalation criteria
Contact Supabase support if policies and JWT claims appear correct, yet both client and service_role queries fail or return inconsistent rows. Include the table schema, policy definitions, and request logs.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.