开发者

Copy data from table of one db into table of another db using query (both tables have same structure)

I have two database in the same schema. My db is in Postgres. I want to copy data of any table (i.e开发者_如何学运维 product) of my 1st db into the same table of the 2nd db.

Is it possible to do so using query?


Can't do it as a single SQL command (at least not without dblink), but the easiest way is probably to just use a pipe between two psql's - use COPY on both ends, one sending the data out in CSV format the other one receiving it.


try

insert into db1.table1 select * from db2.table2


It's not possible in vanilla PostgreSQL installation.

If you are able to install contrib modules, use dblink:

INSERT
INTO    product
SELECT  *
FROM    dblink
        (
        'dbname=sourcedb',
        '
        SELECT  *
        FROM    product
        '
        ) AS p (id INT, column1 INT, column2 TEXT, …)

This should be run in the target database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜