Using RLS for CLS
Hi,
I wanted to know if it is acceptable to use RLS for CLS.
Basically, I create an UPDATE policy that makes sure other columns remain the same as old record except only allowing 2 certain columns to be different.
In effect, I am enforcing column level security. I do understand the fact that i will have to fetch the row each time I want to update. But this trade-off should be acceptable right?
10 Replies
Yes you can and you can also use a trigger function for that too.
Trigger function is what I use.
alright thanks
is this fine?
You just need to set existing columns to the old value and allow the new columns to be updated. This looks like you are raising an exception which will stop all execution henceforth.
can you elaborate? I am not the DB guy tbh
what's wrong with that script? I shouldn't raise an exception if the values differ you mean?
this is fine?
Stack Overflow
PostgreSQL trigger to avoid update in a column
I have a PostgreSQL database with a table called product. In this table I have an autoincrement column named auxId (not the table's primary key). I want to avoid any update on this column. How can ...
Do note that using a trigger function will block updating on that table for these columns no matter what method you use to update. So if you try and update these columns with the dashboard they won't update, if you try to do so with the service_role key they won't update and even with SQL they won't update. So you should really think if this is the desired outcome you are after as we've only shared a solution based on the limited information you shared here.
ah, i think it's better to stick to RLS as it seems better to me
RLS will do the same as your raising of an exception in the trigger function with the caveat that you can bypass it via the dashboard or using the
service_role
key. But as I stated above you gave a limited amount of information so the answers we provide are based on that. There are ways to disable triggers temporarily.okay got it!