How to create a constraint check which ensures that parent_id column doesn't contain any element of child_id column ?
I tried this:
ALTER TABLE myschema.mytable
ADD CONSTRAINT parent_cannot_be_child
CHECK (
child_id NOT IN (
SELECT parent_id FROM myschema.mytable
)
)
But I get this error message:
ERROR: cannot use subquery in check constraint