0

I am writing some c code to transfer data from database_1, table_1 to database_2, table_2. I am quite new to postgresql and unable to figure out how to do this. I am using postgres-9.5

Is the below syntax correct?

psql database_1 -c 'COPY table_1 TO stdout' | psql database_2 -c 'COPY table_2 FROM stdin'

The intelligent guys here, please help me with the correct syntax. Thank you in advance!!

  • That should work just fine. What error messages do you get? Could it be that one of the connections requires a password? – Laurenz Albe Jun 24 '16 at 14:06

1 Answers1

0

not sure why you don't try yourself, but yes - this should work:

postgres=# create database database_1;
CREATE DATABASE
postgres=# create database database_2;
CREATE DATABASE
postgres=# \c database_1
You are now connected to database "database_1" as user "vao".
database_1=# create table table_1 (i int);
CREATE TABLE
database_1=# \q
Vaos-MacBook-Air:~ vao$ psql database_2
psql (9.5.3)
Type "help" for help.
database_2=# create table table_2 (i int);
CREATE TABLE
database_2=# \q
Vaos-MacBook-Air:~ vao$ psql database_1 -c 'COPY table_1 TO stdout' | psql database_2 -c 'COPY table_2 FROM stdin'
COPY 0
Vao Tsun
  • 47,234
  • 13
  • 100
  • 132