-3

I need to check whether row-level-security applies to the current_user in a Postgres query. As far as I can tell, I need to check whether the current user is the owner of that table, or has the BYPASSRLS attribute, or is member of a role that has this. That group membership check seems cumbersome though, especially considering the NOINHERIT attribute of some roles… How to achieve this?

1 Answer 1

4

I need to check whether row-level-security applies to the current_user

Indeed there is a much simpler way to check that - in particular for a specific table, which the user (or one of the inherited roles) might be owner of. The solution is to use the row_security_active function:

row_security_active checks whether row level security is active for the specified table in the context of the current_user and environment. The table can be specified by name or by OID.

So just use

SELECT row_security_active('schema.table');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.