比方說,我們有這個定義的表:如何在PosgreSQL數據庫中聲明範圍重疊約束?
range (
id bigint primary key,
colourId int references colour(id),
smellId int references smell(id),
from bigint,
to bigint
)
該表實際上是在巨大的大桌子減少的觀點:
item (
id bigint primary key,
colourId int references colour(id),
smellId int references smell(id),
CONSTRAINT item_colour_smell_unique UNIQUE (colour, smell, id)
)
我想在range
表翻譯item_colour_smell_unique
約束。它應該觀察範圍[from, to]
的重疊,同時採取colourId
和smellId
列值。