COPY data at Client Side in PG.

Lot of People think that COPY is only a Server Based Command.

However its not completely true.

User can copy the data of a table at client side using COPY Command. The Difference is only in syntax usage.

User has to use backSlash before COPY Command as given below:
testdb=# select * from test;
 id 
----
  1
  2
  3
(3 rows)

testdb=# \copy test to '/tmp/test.copy'
testdb=# \q

We can see output of a file at Client side as given below:
cat /tmp/test.copy 
1
2
3

Similarly User can also copy the data in a file to Server using \COPY as given below:
\COPY test from '/tmp/test.copy'

iclive1460=# \COPY test from '/tmp/test.copy'
iclive1460=# select * from test;
 id 
----
  1
  2
  3
  1
  2
  3
(6 rows)


Note::One should remember while using \COPY Command, one should not terminate command with semicolon ';'

Comments

Popular posts from this blog

xDB Replication from Oracle to PPAS

Does UPDATE Change ROWID in Oracle?

PostgreSQL Database Link to Oracle Database on Linux