Alter a unique index to set it deferrable in postgresq
·
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;
更多推荐
所有评论(0)