```-------------------------------------------------------------------------------------------------------
--##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
-------------------------------------------------------------------------------------------------------```