我做了一個約束,將列completed
的列標記爲true
其他列的某些列必須具有值。基於單列未約束的列的約束
但由於某種原因,當我將completed
標記爲true
時,當我離開指定的列空白時,約束不會發生抱怨。我也故意插入NULL指定的列,仍然沒有約束。
任何想法?
CREATE TABLE info (
id bigserial PRIMARY KEY,
created_at timestamptz default current_timestamp,
posted_by text REFERENCES users ON UPDATE CASCADE ON DELETE CASCADE,
title character varying(31),
lat numeric,
lng numeric,
contact_email text,
cost money,
description text,
active boolean DEFAULT false,
activated_date date,
deactivated_date date,
completed boolean DEFAULT false,
images jsonb,
CONSTRAINT columns_null_check CHECK (
(completed = true
AND posted_by != NULL
AND title != NULL
AND lat != NULL
AND lng != NULL
AND contact_email != NULL
AND cost != NULL
AND description != NULL
AND images != NULL) OR completed = false)
);
嘗試使用測試'IS NOT NULL'但不是'= NULL'! –