小编Kin*_*ull的帖子

根据另一个值更改列的约束

是否可以根据另一列的值更改 postgres 中列的约束?例如(伪代码):

CREATE TABLE transactions(
    id SERIAL PRIMARY KEY,
    type TXN_TYPE NOT NULL,
    amount BIGINT,
    . . . .,
    refunded boolean DEFAULT FALSE,
    refund_id DEFAULT NULL if (CONSTRAINT link_refund CHECK (refunded=TRUE))=TRUE REFERENCES transactions(id)
);
Run Code Online (Sandbox Code Playgroud)

postgresql constraint condition check-constraints

6
推荐指数
1
解决办法
6901
查看次数

外键是否具有唯一性

FOREIGN KEYs是否强加了所指对象的唯一性?即,如果我有一个引用UNIQUE受限列的外键,该FOREIGN KEY列是否是唯一的?我特别想知道 postgresql。

postgresql foreign-key unique-constraint

0
推荐指数
1
解决办法
754
查看次数