更改唯一索引以使其在postgresq中可延期

Gui*_*mas 2 postgresql postgresql-9.6

我需要更改已经创建的唯一索引以将其设置为可延迟。在postgres 9.6中。基本上,我做类似的事情:

DROP TABLE IF EXISTS test;

CREATE TABLE test (id integer);

ALTER TABLE test ADD CONSTRAINT unique_id unique(id);

ALTER TABLE test ALTER CONSTRAINT unique_id DEFERRABLE INITIALLY DEFERRED;
Run Code Online (Sandbox Code Playgroud)

但是我明白了

ERROR:  constraint "unique_id" of relation "test" is not a foreign key constraint
Run Code Online (Sandbox Code Playgroud)

文档似乎没有提到无法执行此操作。我想念什么?

kli*_*lin 5

根据文档:

改变约束

此表单更改了先前创建的约束的属性。当前,只有外键约束可以更改。

相反,您可以:

ALTER TABLE test DROP CONSTRAINT unique_id;
ALTER TABLE test ADD CONSTRAINT unique_id unique(id) DEFERRABLE INITIALLY DEFERRED;
Run Code Online (Sandbox Code Playgroud)