如何在Postgres 8.2中禁用参照完整性? [英] How do I disable referential integrity in Postgres 8.2?

查看:89
本文介绍了如何在Postgres 8.2中禁用参照完整性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google在这方面的结果有点薄,但是建议这不太容易。

Google results on this one are a bit thin, but suggest that it is not easily possible.

我的具体问题是我需要将ID重新编号为两个相互关联的表,以使表B中具有 table_a_id列。我无法先对表A重新编号,因为然后表B中的子级指向旧ID。我无法先对表B重新编号,因为在创建新ID之前,它们将指向新ID。现在重复三到四个表。

My specific problem is that I need to renumber the IDs in two tables that are related to each other such that table B has an "table_a_id" column in it. I can't renumber table A first because then its children in B point to the old IDs. I can't renumber table B first because then they would point to the new IDs before they were created. Now repeat for three or four tables.

当我只是开始交易;禁用ref完整性;排序时,我真的不想摆弄个人关系。 ID出;重新启用参考完整性;提交事务。 Mysql和MSSQL都提供此功能IIRC,所以如果Postgres不提供,我会感到惊讶。

I don't really want to have to fiddle around with individual relationships when I could just "start transaction; disable ref integrity; sort IDs out; re-enable ref integrity; commit transaction". Mysql and MSSQL both provide this functionality IIRC so I would be surprised if Postgres didn't.

谢谢!

推荐答案

似乎不可能。其他建议几乎总是指向删除约束并在完成工作后重新创建约束。

It does not seem possible. Other suggestions almost always refer to dropping the constraints and recreating them after work is done.

但是,似乎可以使约束 DEFERRABLE ,这样直到事务结束才检查它们。有关创建表 PostgreSQL文档。 c> (搜索可延期,它在页面中间)。

However, it seems you can make constraints DEFERRABLE, such that they are not checked until the end of a transaction. See PostgreSQL documentation for CREATE TABLE (search for 'deferrable', it's in the middle of the page).

这篇关于如何在Postgres 8.2中禁用参照完整性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆