我有一个PostgreSQL表1 a9 m6 E# V0 h% A% n
CREATE TABLE my_table( id serial NOT NULL, name text, actual boolean DEFAULT false, CONSTRAINT my_table_pkey PRIMARY KEY (id),);如何设置一行?actual设置为标志的约束TRUE?& [5 V& N% O& d$ }1 n! @. C
2 `' V1 e- ^. R2 D+ Z0 k$ u 解决方案: ! I, r5 E- I `$ r! E# k6 E
您只能为列表中的唯一值创建唯一的索引:+ b: n/ V$ Y- ?1 B
create unique index on my_table (actual) where actual = true;SQLFiddle:http v# Q; r: [+ l' G://sqlfiddle.com/#!15/91f62/1