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 ‘;’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s