dblink 多数据库数据操作

当前数据库为Temp;

希望从数据库qohdb查询数据,导入表groups中。

INSERT INTO groups
SELECT * FROM
dblink('host=127.0.0.1 user=sfuser password=kaisenmaru dbname=qohdb'::text, 'select * from groups'::text)
AS t1(groupid bigint, groupname group_name);

CREATE VIEW qohdbClient AS
SELECT groupid, clientid from
dblink('host=127.0.0.1 user=sfuser password=kaisenmaru dbname=qohdb'::text, 'select groupid, clientid from clients'::text)
AS t2(groupid bigint, clientid bigint);

UPDATE clients SET groupid = qohdbClient.groupid
from qohdbClient
where clients.clientid=qohdbClient.clientid;

DROP VIEW qohdbClient;

posted @ 2012-05-30 08:40  友学友  阅读(266)  评论(0编辑  收藏  举报