以下是已经开始工作的,但它使用的是一个循环:
(我正在更新
nickname, slug
本地表中每行的远程表字段)
DECLARE
row_ record;
rdbname_ varchar;
....
/* select from local */
FOR row_ IN SELECT rdbname, objectvalue1 as keyhash, cvalue1 as slug, cvalue2 as nickname
FROM bme_tag
where rdbname = rdbname_
and tagtype = 'NAME'
and wkseq = 0
LOOP
/* update remote */
PERFORM dblink_exec('sysdb',
format(
'update bme_usergroup
set nickname = %L
,slug = %L
where rdbname = %L
and wkseq = 0
and keyhash = %L'
, row_.nickname, row_.slug, row_.rdbname, row_.keyhash)
);
END LOOP;
现在,我想做的是批量生产
UPDATE (remote) FROM (local)
PERFORM dblink_exec('sysdb',
'update (remote)bme_usergroup
set nickname = bme_tag.cvalue2, slug=bme_tag.cvalue1
from (local).bme_tag s
where bme_usergroup.rdbname = %L
and bme_usergroup.wkseq = 0
and bme_usergroup.keyhash = s.keyhash
and bme_usergroup.rdbname = s.rdbname
)
通过寻找各种解决方案,我已经走到了这一步。(
postgresql: INSERT INTO ... (SELECT * ...)
)我知道如何在
SELECT
,
DELETE
甚至
INSERT/SELECT
. 我也可以用绑定变量直接更新。但是怎么样?
UPDATE FROM
?
如果不可能的话,我应该看看Postgres的
FOREIGN TABLE
或者类似的东西?
本地和远程数据库都在同一个Postgres服务器上。另外还有一点信息,如果重要的话,那就是两个数据库中的任何一个都可以单独删除和还原,我更喜欢一个轻量级的解决方案,它每次都不需要很多配置来重新建立通信。