简体   繁体   English

在PostgreSQL中更新远程表(保持fks)

[英]updating remote tables in postgresql (keeping fks)

I am using pgAdmin III at my work and postgresql at work and at the remote hosting server (webfaction). 我在工作中使用pgAdmin III,在工作中以及在远程托管服务器(webfaction)上使用postgresql。 Through Putty I am creating a tunnel for pgAdmin to work with my local and my remote databases. 通过Putty,我正在为pgAdmin创建一个隧道,以与本地和远程数据库一起使用。 I have a table which primary key is referenced by other tables' keys (as a foreign key). 我有一个表,该表的主键被其他表的键(作为外键)引用。

What is the best way to update that remote table with the values I have on my local table? 用本地表中的值更新该远程表的最佳方法是什么?

What I (unsuccessfully) try to do is 'backup' my local table and then try to 'restore' my remote table with that file. 我(未成功)尝试执行的操作是“备份”本地表,然后尝试使用该文件“还原”我的远程表。 However, pgAdmin III gives me duplicate key value error. 但是,pgAdmin III给了我重复的键值错误。

pg_restore: connecting to database for restore
pg_restore: restoring data for table "main_city"
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 1972; 0 17110 TABLE DATA main_city user
pg_restore: [archiver (db)] COPY failed: ERROR:  duplicate key value violates unique constraint "main_city_pkey"
CONTEXT:  COPY main_city, line 1: "1    London  20  30  4   1"
pg_restore: setting owner and privileges for TABLE DATA main_city
WARNING: errors ignored on restore: 1

Process returned exit code 1.

Shall I try another postgresql client? 我可以尝试另一个postgresql客户端吗? It is a pain if I try to remove all those references and try to update manually. 如果我尝试删除所有这些引用并尝试手动更新,那是很痛苦的。 Any help would be appreciated! 任何帮助,将不胜感激!

我对pgAdmin一无所知,但是如何将文件中的数据添加到临时表中以及如何根据行是否存在将其更新/插入到原始表中呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM