https://supabase.com/ logo
#sql
Title
# sql
j

Jan Tennert

06/03/2022, 4:09 PM
Hey tried to create an rls policy for: Authenticated users can do everything (select, ...) to the product table when the shop specified with a shop_id contains the uid() in an array called authorized users. This doesn't work: (image) It gives me this error: Error adding policy: operator does not exist: uuid = uuid[]
g

garyaustin

06/03/2022, 5:56 PM
Try = ANY(ARRAY(select......))
j

Jan Tennert

06/03/2022, 6:28 PM
thanks the error is now gone. But I tried to get the products and get
Copy code
json
{
    "message": "cannot accumulate empty arrays",
    "code": "2202E",
    "details": null,
    "hint": null
}
In response. The uuid array is empty. Do I have to set anything else?
g

garyaustin

06/03/2022, 6:36 PM
I recommend you debug using the sql editor. I have not compared an array column like this. Is there anyway you can get more than one row back from your shops table based on id?
j

Jan Tennert

06/03/2022, 6:38 PM
no also currently theres only one
g

garyaustin

06/03/2022, 6:48 PM
Yeah, just checked it and ARRAY will error like that with null or empty array. Unfortunately, it is not clear to me why that is even needed if the select column is array (like your original query). I normally use functions with a STABLE type to do my test on other tables and return a boolean true/false/null in my RLS. Then I can use PL/pgSQL and SQL in the function.
j

Jan Tennert

06/03/2022, 7:02 PM
okay thanks
g

garyaustin

06/03/2022, 7:34 PM
@Jan Tennert OK this seems to work.... auth.uid() = any ((select....)::uuid[])
j

Jan Tennert

06/03/2022, 7:40 PM
thank you 👍