COPY statement
In PostgreSQL default functionality, only postgres super user can copy between a table and a diskfile. However, in Pgbash, not only postgres super user but also a general user can copy it .
COPY table( [ col1[,col2..] ] ) {TO|FROM} {'fileame'|STDIN|STDOUT}
[USING DELIMITERS 'delim'] [WITH NULL AS 'nullstring' ];
(1) COPY TO database from file
If you execute "copy tbname(col1,col2) from '/tmp/oo'", the COPY command is changed as follows.
begin;
insert into tbname(col1,col2) values(file's data1);
insert into tbname(col1,col2) values(file's data2);
...
end;
If an error was occurred, then a database is rollbacked.
(2) COPY from database TO file
If you execute "copy tbname(col1,col2) to '/tmp/oo'", the COPY command is changed as follows.
begin;
declare copy_cur00 cursor for select col1,col2 from tbname;
fetch 300 in copy_cur00; >> /tmp/oo
fetch 300 in copy_cur00; >> /tmp/oo
end;