Skip to content
Advertisement

Constraint for self-referencing columns based on row value in another column – postgres

I have a table like

Can I have another constraint on the FOREIGN KEY to check reports_to to be either a manager or a lead?

Advertisement

Answer

You cannot create a foreign key for this check but you can create a check constraint with a function for this:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement