gpt4 book ai didi

sql - DISABLE TRIGGER ALL 是否应该禁用外键约束检查?

转载 作者:行者123 更新时间:2023-11-29 11:28:47 25 4
gpt4 key购买 nike

我正在将数据从一个 PostgreSQL v10 表复制到另一个。目标表有几个外键约束。我很惊讶我没有得到任何错误,即使外键约束引用的表都没有任何数据。

在执行复制之前,我使用了 DISABLE TRIGGER ALL 来确保目标表上定义的触发器不会触发。令我惊讶的是,复制成功了。在 ENABLE TRIGGER ALL 之后,我尝试再添加一行,即现有行的副本。由于违反外键约束而失败。然后我执行了 DISABLE TRIGGER ALL,尝试添加新行,结果成功了。

我得出结论,在 PostgreSQL 10 中,DISABLE TRIGGER ALL 将禁用外键约束检查。这是预期的行为吗?

详情可见here .

最佳答案

是的,这是预期的。

来自 "ALTER TABLE" :

DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER

These forms configure the firing of trigger(s) belonging to the table. (...) One can disable or enable a single trigger specified by name, or all triggers on the table, or only user triggers (this option excludes internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints). Disabling or enabling internally generated constraint triggers requires superuser privileges; it should be done with caution since of course the integrity of the constraint cannot be guaranteed if the triggers are not executed. (...)

关于sql - DISABLE TRIGGER ALL 是否应该禁用外键约束检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51775738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com