Postgresql, Restrict update on specific columns (Read Only)

前端 未结 2 788
野趣味
野趣味 2021-01-07 19:23

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

相关标签:
2条回答
  • 2021-01-07 20:01

    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.

    0 讨论(0)
  • 2021-01-07 20:01

    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.

    0 讨论(0)
提交回复
热议问题