7 ms·
> Users can edit x,y,z columns on the comments table, if they were the ones that wrote them and the comment does not have a lock flag GRANT UPDATE (subject, te
by floatboth 10y ago
> Users can edit x,y,z columns on the comments table, if they were the ones that wrote them and the comment does not have a lock flag
GRANT UPDATE (subject, text) ON comments TO user;
CREATE POLICY comments_update_own_not_locked ON comments FOR UPDATE TO user
USING (locked IS NOT TRUE AND created_by = current_setting('postgrest.claims.username'))
WITH CHECK (created_by = current_setting('postgrest.claims.username'));
Row-level security in Postgres is awesome!
- jakewins 10y agoHoly crap, I hadn't realized just how powerful RLS ended up - last time I looked at this was before 9.5 and it was roles all the way down.. That is fantastic! That's exactly what I wanted. I guess it's true as they say, that the easiest way to get the right answer on the internet is to publish the wrong answer :)
- ruslan_talpa 10y agoThe features provided by RLS are not really new, they just add a nice syntax to define the rules. All the things you mentioned can be implemented using roles and views.
- ruslan_talpa 10y agoBe careful, RLS and views don't play well together, that is to say, your policies on a table for a particular user will not be applied if that tables is accessed through a view.