Sunday 13 November 2011

copy command usage in postgres


copy data from file to table:
---------------------------------------

copy vacuumtest from  '/home/postgres/test1.csv' with delimiter ',' CSV ;

copy data from table to a file:
-----------------------------------------
copy (select * from vacuumtest) to '/home/postgres/test1.csv' with delimiter ',' CSV;

 

copy data from file to table with headers information :
-----------------------------------------------------------------------------
copy vacuumtest from  '/home/postgres/test1.csv' with delimiter ',' CSV header;

copy data from table to a file with headers information:
-------------------------------------------------------------------------------
copy (select * from vacuumtest) to '/home/postgres/test1.csv' with delimiter ',' CSV header ;


copy standard input into a table:
-----------------------------------------------
Eg1 :  COPY abc (id) FROM stdin; 
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1
>> 2
>> 3
>> 4
>> 5
>> \.

Eg2:COPY test2 (id, name, loc) FROM stdin with delimiter ',';
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1,rc2,chiranjeevi
>> \.




No comments:

Post a Comment