Hey tried to create an rls policy for: Authenticat...
# sql
j
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
Try = ANY(ARRAY(select......))
j
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
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
no also currently theres only one
g
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
okay thanks
g
@Jan Tennert OK this seems to work.... auth.uid() = any ((select....)::uuid[])
j
thank you 👍