Select returning empty array on project but query works on supabase site
Updating, creating, and deleting work only select returns an empty array. I've tried the exact query on the Supabase site itself, and it works, returning the right number of rows. However, on the Node.js server, it doesn't. I have disabled RLS, enabled RLS, added a policy, and yet the problem persists.
15 Replies
You'll need to show your RLS policies. Querying data after disabling RLS should've worked.
If you're querying through the PostgREST API, the table also has to be in a publicly exposed schema.
I believe it wouldn't have returned empty array otherwise.
Good point, you might be right there.
This is the policy I am using.
also I'm using this library to query supabase
GitHub
GitHub - porsager/postgres: Postgres.js - The Fastest full featured...
Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare - porsager/postgres
Show the query you make using this lib
TO
clause.public
. I meant the FOR
.
The exact query thats being sent is
SELECT * FROM COMMENTS WHERE comment_id IN ('https://www.youtube.com/watch?v=mWDOPcFKsfg&lc=Ugxywn7APVAEHPVgyXN4AaABAg','https://www.youtube.com/watch?v=mWDOPcFKsfg&lc=UgwNZEGTE8dxz9MxHup4AaABAg&pp=0gcJCSIANpG00pGi')
which works on supabaseAnd as fieryduck mentioned, show the full policy.
I cant seem to find it

The SELECT policy looks permissive enough. Can you try querying all rows from the Node?
SELECT * FROM comments
When you login as postgres user with a direct connection string, RLS policies are bypassed.
Use a simple query with a LIMIT. I believe its an issue with your query
For RLS to take effect with a direct connection refer to this thread. https://discord.com/channels/839993398554656828/1351855856450408518
Not related to the issue at hand, and I have not used Postgres.js before, but based on what I read in the docs, the way you're constructing the
IN ARRAY
seems to be vulnerable to an SQL injection (see note).it was 100% an issue with the query I wasnt following their advice properly in documentation when it came to arrays. Also I changed it from an "IN" statement to an "ANY" statement and it works like a charm. Thank you guys for your help