【问题标题】:Alter a unique index to set it deferrable in postgresq更改唯一索引以在 postgresql 中将其设置为可延迟
【发布时间】:2018-11-10 22:50:19
【问题描述】:

我需要更改已创建的唯一索引以将其设置为可延迟。在 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

文档似乎没有提到无法执行此类操作。我错过了什么?

【问题讨论】:

    标签: postgresql indexing unique postgresql-9.6


    【解决方案1】:

    the documentation:

    改变约束

    这种形式改变了先前创建的约束的属性。目前只能更改外键约束。

    相反,您可以:

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

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 2018-08-13
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      相关资源
      最近更新 更多