无法向 table 添加排除约束

Unable to add exclude constraint to table

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

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 位编译

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