COPY Command in PostgreSQL data Import and Export

Published: 11 January 2020
on channel: DatabaseLibrary
1,435
1

```-------------------------------------------------------------------------------------------------------
--##copy command in PostgreSQL (import and export data)
drop table if exists tmp_source;
select tablename,schemaname into temp tmp_source from pg_tables limit 10 ;
\copy (SELECT * from tmp_source ) to 'tmp_source.csv' (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *);
--\copy (SELECT * from tmp_source) to 'tmp_source.txt' (FORMAT CSV,DELIMITER('|'), HEADER TRUE, FORCE_QUOTE *);
--\copy (select col1,col2,col3 from tmp_source where activeflag is true) to 'tmp_source.csv' (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *);

drop table if exists tmp_target;
create TEMP table tmp_target (tablename text,schemaname text);
\COPY tmp_target FROM 'tmp_source.csv' DELIMITER ',' CSV HEADER ;
select * from tmp_target;
insert into final_table select * from tmp_target;
-\COPY tablename(col1,col2,col3) FROM 'tmp_source.csv' DELIMITER ',' CSV HEADER ;- for other format
-------------------------------------------------------------------------------------------------------```


On this page of the site you can watch the video online COPY Command in PostgreSQL data Import and Export with a duration of hours minute second in good quality, which was uploaded by the user DatabaseLibrary 11 January 2020, share the link with friends and acquaintances, this video has already been watched 1,435 times on youtube and it was liked by 1 viewers. Enjoy your viewing!