比方说,我们有这个定义的表:如何在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
列值。