更改唯一索引以在 postgresql 中将其设置为可延迟
Alter a unique index to set it deferrable in postgresq
我需要更改已创建的唯一索引以将其设置为可延迟。在 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;
但是我明白了
ERROR: constraint "unique_id" of relation "test" is not a foreign key constraint
文档似乎没有提到无法执行此类操作。我错过了什么?
ALTER CONSTRAINT
This form alters the attributes of a constraint that was previously created. Currently only foreign key constraints may be altered.
相反,您可以:
ALTER TABLE test DROP CONSTRAINT unique_id;
ALTER TABLE test ADD CONSTRAINT unique_id unique(id) DEFERRABLE INITIALLY DEFERRED;
我需要更改已创建的唯一索引以将其设置为可延迟。在 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;
但是我明白了
ERROR: constraint "unique_id" of relation "test" is not a foreign key constraint
文档似乎没有提到无法执行此类操作。我错过了什么?
ALTER CONSTRAINT
This form alters the attributes of a constraint that was previously created. Currently only foreign key constraints may be altered.
相反,您可以:
ALTER TABLE test DROP CONSTRAINT unique_id;
ALTER TABLE test ADD CONSTRAINT unique_id unique(id) DEFERRABLE INITIALLY DEFERRED;