Im having some problems writing a Row Level Policy...
# help
l
Im having some problems writing a Row Level Policy for the following: I have a
users
table. A user has an
id
field (foreign key on
auth.oid()
) and also a
company_id
I want to write a RLP such that a user can select the row for any other user provided they are in the same company (i.e have the same
company_id
) I wrote the following statement, but the problem is that I get an infinite recursion error (which makes sense). Anyone know how I would be able to achieve my desired RLP?
Copy code
(id = uid()) OR (company_id = ( SELECT users_1.company_id
   FROM users users_1
  WHERE (users_1.id = uid())
 LIMIT 1)))
n
Hello @Lior539! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! 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.
l
I was able to figure it out: I put the above sql code in a function and then used the advanced settings to set the security to DEFINER instead of INVOKER
is this the best way? Is there a better way?
g
I answered this in your sql thread. Please do not double post questions.