Is it possible to have postresql restrict/prevent an update on a specific record if the update includes changes to specific columns?
How would this be implemented. A trigger/constraint? What would be the most efficient way to implement this?
I am using version 9.1
First, specify the name of the table that you want to update data after the UPDATE keyword. Second, specify columns and their new values after SET keyword. The columns that do not appear in the SET clause retain their original values. Third, determine which rows to update in the condition of the WHERE clause.
Updatable Views. Simple views are automatically updatable: the system will allow INSERT , UPDATE and DELETE statements to be used on the view in the same way as on a regular table.
The SELECT FOR UPDATE statement is used to order transactions by controlling concurrent access to one or more rows of a table. It works by locking the rows returned by a selection query, such that other transactions trying to access those rows are forced to wait for the transaction that locked the rows to finish.
The easiest way is to create BEFORE UPDATE
trigger that will compare OLD
and NEW
row and RAISE EXCEPTION
if the change to the row is forbidden.
No, but it should be pretty trivial to write.
Just set up a BEFORE UPDATE
trigger that compares old field against new field and does a RAISE ERROR
if they're different.
The pgSQL docs have a few examples of how to write a trigger function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With