我正在创建一个这样的表:
CREATE TABLE artist (
Id serial PRIMARY KEY,
NameNormalized varchar(256) NOT NULL UNIQUE,
Name text NOT NULL,
MusicBrainzId char(36) NULL,
Rating DECIMAL(2,1),
CONSTRAINT non_empty CHECK (length(NameNormalized) > 0 and length(Name) > 0)
);
当我尝试执行以下INSERT操作时,出现错误:
INSERT INTO artist (NameNormalized, Name, MusicBrainzId, Rating)
VALUES ('test', 'Test', '123456789012345678901234567890123456', 0.5)
ON CONFLICT (NameNormalized) DO NOTHING;
错误消息如下:
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
我做了一些研究,但据我所知,将NameNormalized设置为UNIQUE应该足以让ON CONFLICT工作。另外我很确定这对我来说过去是有效的。