【发布时间】:2016-04-07 10:05:30
【问题描述】:
我有一张桌子
CREATE TABLE mandantconfigentity
(
id bigint NOT NULL,
currentlegalversionnumber integer NOT NULL DEFAULT 5,
belongsto_userid character varying(255)
)
如何创建一个唯一索引,以确保该表只能有一行,其中 belongsto_userid 为空?
这不起作用:
CREATE UNIQUE INDEX unique_mandantconfig_for_null_belongsto
ON mandantconfigentity (1)
WHERE (belongsto_userid IS NULL);
【问题讨论】:
标签: sql postgresql unique-constraint