【问题标题】:Unable to add exclude constraint to table无法将排除约束添加到表
【发布时间】:2018-11-28 22:16:44
【问题描述】:

我无法使用此架构创建排除索引。

create table foo_bar(
    foo_id text primary key,
    bar char(3) not null,
    created_at timestamptz not null default current_timestamp,
    system_period tstzrange not null default tstzrange(current_timestamp, null),
    exclude using gist (system_period with &&)
);

create table foo_bar_history(like foo_bar);

alter table foo_bar_history add constraint exclude using gist (system_period with &&);

这里最后的 alter table 行失败了

SQL Error [42601]: ERROR: syntax error at or near "using"

我已经仔细检查了文档,但我真的看不出我在这里做错了什么。

x86_64-pc-linux-gnu 上的 PostgreSQL 9.6.9,由 gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0 编译,64 位

【问题讨论】:

    标签: postgresql ddl exclusion-constraint


    【解决方案1】:

    您要么必须在 CONSTRAINT 之后指定约束名称,要么完全省略该关键字,以便 PostgreSQL 自己选择一个名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 2019-11-11
      相关资源
      最近更新 更多