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

I have two databases in the same schema. My db is in Postgres. I want to copy data from any table (for example, a product) of my 1st db into the same table of the 2nd category.

Is it possible to do this with a query?

+3
source share
3 answers

It is impossible to do this as a single SQL command (at least not without dblink), but the easiest way is probably just to use the channel between two psql - use COPY at both ends, one sends data in CSV format the other receives it.

+3
source

to try

insert into db1.table1 select * from db2.table2
0

PostgreSQL.

Contrib, dblink:

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

.

0
source

Source: https://habr.com/ru/post/1765253/


All Articles