【发布时间】:2018-08-13 10:27:59
【问题描述】:
我有一个带有唯一索引
的 PostgreSQL 表CREATE SEQUENCE public.batterysensorhistory_id_seq NO MINVALUE NO
MAXVALUE NO CYCLE;
CREATE TABLE batterysensorhistory
(
id integer DEFAULT
nextval('batterysensorhistory_id_seq'::regclass) PRIMARY KEY NOT NULL,
batteryid uuid NOT NULL,
sensorid integer NOT NULL,
isactivelink boolean DEFAULT false NOT NULL,
...
);
create unique index on batterysensorhistory (batteryid, sensorid, isactivelink)
where isactivelink = TRUE;
我想设置一个约束,只有具有相同电池 ID && 传感器 ID 的一行可以具有 isactivelink = true,但我的 唯一索引 不起作用。
另外,我在 sqlfiddle 中创建了这个示例:http://sqlfiddle.com/#!15/c3b37/1
知道我的代码有什么问题吗?
【问题讨论】:
标签: sql postgresql indexing unique unique-index