postgresql:提取包含所有 fk 引用的单个记录
我使用大型 postgresql 生产数据库。有时需要使用实际生产数据进行调试。由于数据库的大小,将整个转储传输到我们的开发工作站是不切实际的。
有没有办法,也许使用 information_schema 来提取单个记录,以及:
此记录引用的所有记录,递归级联
所有记录引用此记录的所有记录(也将先前的标准应用于这些记录)
也许最好用一个例子来说明:
如果我们有以下表:
People(fk 到 Addresses)
Addresses(fk 到 Cities)
Cities
Employees(fks 到 Employee_Types, People)
Employee_Types
假设我想“提取”People 表中的特定记录。我想获得:
(1) 人员中的记录
(2) (1) 中的人员记录引用的地址中的记录 (3)
(2) 中的地址记录引用的城市中的记录
(4) 任何员工引用 (1) 中 People 记录的记录
(5) 由 (4) 中找到的 Members 记录引用的 Employee_Types 记录
有什么想法吗?
I work with a large postgresql production database. Occasionally there is a need to debug using actual production data. Because of the size of the database, it is impractical to transfer an entire dump to our development workstations.
Is there a way, perhaps using the information_schema, to extract a single record, as well as:
all records referenced by this record, cascaded recursively
all records that refer to this record (with previous criterion applied to these records as well)
Maybe best illustrated with an example:
If we have the following tables:
People (fk to Addresses)
Addresses (fk to Cities)
Cities
Employees (fks to Employee_Types, People)
Employee_Types
Say that I want to 'extract' a particular record in the People table. I would want to get:
(1) the record in People
(2) the record in Addresses referenced by the People record in (1)
(3) the record in Cities referenced by the Addresses record in (2)
(4) any Employees record that refers to the People record in (1)
(5) the Employee_Types records that are referenced by the Employees records found in (4)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个包含与这些人相关的所有记录的转移表:
然后在最后插入到相应的表中,注意正确的顺序以避免外键错误:
Create a transfer table with all the records related to those persons:
Then at the destiny insert into the respective tables with attention to the correct order to avoid foreign key errors: