【问题标题】:Postgresql constraint no overlap between timestampsPostgresql 约束在时间戳之间没有重叠
【发布时间】:2020-04-12 00:36:57
【问题描述】:

我正在尝试创建一个包含营业时间的表格(用于自助餐厅) 但是,我在实施约束时遇到了一些问题。每个餐厅的营业时间不能重叠。

CREATE table openinghours(
    id serial PRIMARY key,
    start timestamp NOT NULL,
    duration interval NOT NULL,
    resto_naam varchar REFERENCES resto(naam),
    constraint openingstijden_duplicate_check EXCLUDE USING GIST (
        resto_naam WITH =,
        /* Check wether there is no overlap between the dates */
        tsrange(start, start + duration) WITH &&
    )
);

当我尝试执行此 SQL 时,我收到以下错误:

错误:数据类型字符变化没有访问方法“gist”的默认运算符类 提示:您必须为索引指定一个运算符类或为数据类型定义一个默认运算符类。 SQL 状态:42704

任何帮助将不胜感激!

【问题讨论】:

    标签: sql postgresql timestamp constraints


    【解决方案1】:

    您需要 btree_gist 扩展才能使其工作。执行create btree_gist 并重试。

    最好的问候,
    比亚尼

    【讨论】:

      猜你喜欢
      • 2020-07-13
      • 1970-01-01
      • 2017-05-12
      • 2018-07-10
      • 2011-12-14
      • 1970-01-01
      • 2018-03-27
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多