1

I have a nullable column whose values are taken from an enum. I want to define that column's default value based on another column's value.

For example, given the following table:

name | type | status
-----|------|-------
abcd | t1   | null
efg  | t2   | s1

The status column is based on an enum and can be nullable.

can I somehow define that the default value of status should be

s1 if type==t1 else null

Postgres version = 13.4

Eliran Turgeman
  • 1,526
  • 2
  • 16
  • 34
  • 2
    You need a trigger for that. Default values can not be based on other columns. –  Feb 26 '23 at 10:48

0 Answers0