一列的值不能包含在另一列中,反之亦然

时间:2019-04-27 23:05:30

标签: postgresql postgresql-9.4

我具有以下结构:

CREATE TABLE users (
    id bigserial PRIMARY KEY,
    parent_id bigint REFERENCES users(id),
    left_id bigint REFERENCES users(id) UNIQUE,
    right_id bigint REFERENCES users(id) UNIQUE,
);

left_id值不能包含在right_id的任何行中

right_id值不能包含在right_id的任何行中

如何为这种情况创建约束?

0 个答案:

没有答案