Skip to content

Instantly share code, notes, and snippets.

@linxuedong
Created September 19, 2018 07:05
Show Gist options
  • Save linxuedong/3e608518ecd2dede25d38f032167c450 to your computer and use it in GitHub Desktop.
Save linxuedong/3e608518ecd2dede25d38f032167c450 to your computer and use it in GitHub Desktop.
#postgres

查询导出 CSV 文件

\copy (select * from t1) To 'filename.csv' With CSV HEADER

OR

COPY (select * from t1) TO '/var/lib/postgresql/f.csv' WITH CSV HEADER;

REF sql - Save PL/pgSQL output from PostgreSQL to a CSV file - Stack Overflow

时间格式时区

select create_time from t limit 1;
      create_time
------------------------
 2018-09-15 03:46:52+00
(1 row)

select timezone('Asia/Shanghai', create_time) from t limit 1;
      timezone
---------------------
 2018-09-15 11:46:52
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment