Answer a question

I need to alter a unique index which has already been created to set it deferrable. In postgres 9.6. Basically, i do something like:

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;

But i get

ERROR:  constraint "unique_id" of relation "test" is not a foreign key constraint

Documentation does not seem to mention that such action cannot be performed. What am i missing?

Answers

Per the documentation:

ALTER CONSTRAINT

This form alters the attributes of a constraint that was previously created. Currently only foreign key constraints may be altered.

Instead you can:

ALTER TABLE test DROP CONSTRAINT unique_id;
ALTER TABLE test ADD CONSTRAINT unique_id unique(id) DEFERRABLE INITIALLY DEFERRED;
Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐