Hey, can I apply two conditions to a RLS statement...
# help
p
Hey, can I apply two conditions to a RLS statement using
OR
? like this:
((is_public = true) OR (uid() = user_id))
n
Hello @Prodigy7kX! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
s
Yes, you can. You can use any SQL statement for an RLS policy as long as it returns a boolean
n
Prodigy7kX (2022-03-22)
p
How would i make something like this work? I did some googling and tried a bunch of stuff but i couldn't get it to work...
s
What error are you getting when you tried what you have above?
p
no errors, I'm just not getting rows where
is_public = false
what I tried to do with the RLS is: I'm trying to get rows where either
is_public = true
or
uid() = user_id
, if either of these is true I should be able to select the row
s
Flip the query and it should work
((uid() = user_id) OR (is_public = true))
p
lemme check
nope, still not selecting "non public" rows
s
The user you are using to get the data is allowed to view those rows?
p
yep
s
There's definitely something else going on with your table. Try running this in the SQL console:
Copy code
sql
SELECT
    column_name,
    data_type,
    column_default AS default_value,
    is_generated
FROM
    information_schema.columns
WHERE
    table_name = 'users'
    AND table_schema = 'public'
(replace the
table_name
and
table_schema
with appropriate values) That'll tell us how your table is structured, as well as what the data type of each column is.
p
ok