https://supabase.com/ logo
#help
Title
# help
p

Prodigy7kX

03/22/2022, 2:49 AM
Hey, can I apply two conditions to a RLS statement using
OR
? like this:
((is_public = true) OR (uid() = user_id))
n

Needle

03/22/2022, 2:49 AM
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

Scott P

03/22/2022, 2:51 AM
Yes, you can. You can use any SQL statement for an RLS policy as long as it returns a boolean
n

Needle

03/22/2022, 2:51 AM
Prodigy7kX (2022-03-22)
p

Prodigy7kX

03/22/2022, 3:15 AM
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

silentworks

03/22/2022, 10:33 AM
What error are you getting when you tried what you have above?
p

Prodigy7kX

03/22/2022, 2:37 PM
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

silentworks

03/22/2022, 6:41 PM
Flip the query and it should work
((uid() = user_id) OR (is_public = true))
p

Prodigy7kX

03/22/2022, 6:44 PM
lemme check
nope, still not selecting "non public" rows
s

silentworks

03/22/2022, 7:08 PM
The user you are using to get the data is allowed to view those rows?
p

Prodigy7kX

03/22/2022, 7:43 PM
yep
s

Scott P

03/22/2022, 7:50 PM
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

Prodigy7kX

03/22/2022, 8:02 PM
ok