我有下面的示例表定义。是否可以创建一个检查约束,其中受影响的列可以为空?
CREATE TABLE task (
# other definition
registered_date timestamp without time zone NOT NULL,
completed_date timestamp without time zone
# constraints
);
我计划暗示对 completed_date
进行约束检查,以便输入值不会小于registered_date
。这可能吗?
最佳答案
是的。检查约束自动接受 NULL 值。 Per documentation:
It should be noted that a check constraint is satisfied if the check expression evaluates to true or the null value. Since most expressions will evaluate to the null value if any operand is null, they will not prevent null values in the constrained columns. To ensure that a column does not contain null values, the not-null constraint described in the next section can be used.
我的粗体强调。
关于sql - PostgreSQL 检查约束是否相关列可为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22342536/