Why is my select returning an empty data array and I have data in the table?

Last edited: 1/16/2025

Usually this means you have RLS (row level security) enabled and no policy, or do not meet the policy. It can also mean you have a filter and have no rows matching that.

If you have RLS enabled you can test quickly by disable RLS on the table. If your query works then you have no policies or do not meet them.

If you have policies that depend on having a signed in user (TO set to authenticated or using auth.uid()) then you can check by setting TO as anon and setting your policy to just TRUE. If that works then you don't have a signed in user (with a jwt in the authorization header) when you make the call.

For more information on RLS please see https://supabase.com/docs/guides/auth/row-level-security

Adding: To test if you have a user session at time of your call you can add this function with the SQL editor and an rpc call in your code at same place as your current database call.


_10
create function test_authorization_header() returns json
_10
language SQL
_10
as
_10
$$
_10
select auth.jwt();
_10
$$;


_10
const { data: testData, error: testError } = await supabase.rpc('test_authorization_header')
_10
console.log(`The user role is ${testData.role} and the user UUID is ${testData.sub}. `, testError)

If you have anon or service_role as the role then you do not have a user session at the time of your call.

To delete the test SQL function:


_10
drop function test_authorization_header;