postgresql导出导入


导出CSV:

------------
导出:

COPY e_m_city (name, email) TO '/home/chenhao1/employee.csv' CSV HEADER;

\COPY e_m_city  TO '/home/postgres/e_m_city.csv' CSV HEADER;

导入文件数据,指定间隔符为 | :

COPY employeenew FROM '/home/smallfish/employee.sql' DELIMITER |;


psql
\o /tmp/test.out
select *  from report.cinematicketinf  t right join report.cinema c on c.cinemacode=t.cinemacode where t.playtime >='2015-10-08' and t.playtime < '2015-10-09';


案例:SQL查询结果导出CSV

方法1:
 \f ','
 \a
\o /tmp/m_film.csv
select recordid ,movieid from   m_film where movieid is not null;

 sz m_film.csv

方法2:
 \COPY (select recordid ,movieid from   m_film where movieid is not null) TO '/tmp/m.csv' CSV HEADER;



导入: 
 \COPY m_film from  '/tmp/m.csv' WITH CSV HEADER;

请使用浏览器的分享功能分享到微信等