I need to copy data from one table to another. the two tables have almost the same structure, but are in different databases.
i tried
INSERT INTO db1.public.table2(
id,
name,
adress,
lat,
lng
)
SELECT
id,
name,
adress,
lat
lng
FROM db2.public.table2;
wenn i try this, i get error cross database ... not implemented
If you really have two distinct PostgreSQL databases, the common way of transferring data from one to another would be to export your tables (with pg_dump -t ) to a file, and import them into the other database (with psql ).
This is a really straightforward task. Just use dblink for this purpose:
INSERT INTO t(a, b, c)
SELECT a, b, c FROM dblink('host=xxx user=xxx password=xxx dbname=xxx', 'SELECT a, b, c FROM t') AS x(a integer, b integer, c integer)
If you need to fetch data from external database on a regular basis, it would be wise to define a server and user mapping. Then, you could use shorter statement:
dblink('yourdbname', 'your query')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With