0

There is a requirement to have a Postgres table with multiple columns to store audit records.

The table has an Id column populated using autogenerator from sequence(hibernate) for every save. For some purpose, there is a need to have another non-null column added to the table with DEFAULT value as copy of the value from autogenerated Id column (but also allows taking the value when explicitly set).

Found few suggestions - PostgreSQL - set a default cell value according to another cell value , still would like to explore if this can be handled at hibernate/Spring JPA level OR even at column definition level?

Arpit S
  • 137
  • 2
  • 10
  • 2
    It could be done by a trigger, always is faster and more secure to maintain all the operations concerning to a database in the database itself rather than in application logic. – Pepe N O Jun 28 '23 at 20:14
  • There is no other way than a trigger, at least on the database level. – Laurenz Albe Jun 28 '23 at 20:22
  • My [answer to the referenced question](https://stackoverflow.com/a/16754952/939860) still stands for Postgres 15. I suppose this is a duplicate then? – Erwin Brandstetter Jun 28 '23 at 22:10

0 Answers0