Row level security in PostgreSQL for different groups
4
votes
1
answer
1189
views
Need a little help with row-level security in Postgres.
I have several tables and three group roles:
- group1
- group2
- group3
I have several login roles (users) that are members of each group, while "admins" are members of all groups.
i.e.
- group1
- user1_1
- user1_2
- group2
- user2_1
- user2_2
- group3
- user3_1
- user3_2
I would like to enable row-level security such that members of
group1
can only see rows that were created by them or another user in group1
and same for group2
and group3
.
I can easily do this for individual users by creating a row that contains current_user
and using something like:
CREATE POLICY row_policy
ON table1
USING (true)
WITH CHECK (created_by = current_user);
But how does one enable this for different group roles so that every member of that group has the same row-level privileges?
Asked by Cliff
(161 rep)
Sep 6, 2017, 06:25 PM
Last activity: Jul 18, 2024, 08:26 AM
Last activity: Jul 18, 2024, 08:26 AM