CREATE TABLE my_table
(
fk INTEGER,
field_1 INTEGER,
field_2 INTEGER,
field_3 INTEGER
)
VALID:
fk | field_1 | field_2 | field_3
----------+---------------+---------------+---------------
1 | 1 | null | null
1 | null | 1 | null
1 | null | null | 1
It’s possible to create check constraint which allows only 1 field of 3 can be not null for 1 fk ?
It is not quite clear what you’d like to achieve.
If you need only one column being
NOT NULLper row, then Nitram’s answer will do, you can also try:Otherwise, if you need to have only single
NOT NULLcolumn per all rows with the given FK, you should look into theCONSTRAINT TRIGGER, something like this: