如何使用Postgres排除约束以强制执行邻接

发布于 2025-01-18 00:25:50 字数 663 浏览 1 评论 0 原文

假设我有一张桌子放松_SCHEDULE,带有一个varteant_id和一个类型的时间表(或其他任何其他范围),

我知道如何使用排除约束来防止直接相邻,例如:

alter table relaxed_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with -|-);

但是我在寻找的是什么 。因为是一种强制执行杂物相邻的方法,因此相反。是否有接近以下内容?

alter table tight_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with !-|-);

这是一个示例小提琴:

Let's say I have a table relaxed_schedule, with a contestant_id and a timeslot of type daterange (or any other range, really)

I know how to use an exclude constraint to prevent dateranges from being directly adjacent, like so:

alter table relaxed_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with -|-);

But what I'm looking for is a way to enforce that the dateranges are adjacent, so quite the opposite. Is there something that comes close to the following?

alter table tight_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with !-|-);

Here's an example fiddle: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=172bf2ef20b1289318872ee171374abf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文