COPY { 表名 [ ( 列名称 [, ...] ) ] | ( 查询 ) } TO { '文件名' | PROGRAM '命令' | STDOUT }
[ [ WITH ] ( 选项 [, ...] ) ]选项可以是下列内容之一
FORMAT 格式_名称
FREEZE [ 布尔 ]
DELIMITER '分隔字符'
NULL '空字符串'
HEADER [ 布尔 ]
QUOTE '引用字符'
ESCAPE '转义字符'
FORCE_QUOTE { ( 列名称 [, ...] ) | * }
FORCE_NOT_NULL ( 列名称 [, ...] )
FORCE_NULL ( 列名称 [, ...] )
ENCODING 'encoding_name(编码名)'test=# select * from test;user_id | user_name | age | gender | remark ---------+---------------+-----+--------+---------------------------------------------- 1 | Jackie Chan | 45 | male | "police story","project A","rush hour" 3 | Brigitte Li | 46 | female | 4 | Maggie Cheung | 39 | female | 5 | Jet Li | 41 | male | "Fist of Legend","Once Upon a Time in China" 2 | Gong Li | 38 | female | "Farewell My Concubine","Lifetimes Living"(5 行记录)
test=# copy test to '/tmp/test1.csv' with csv header;COPY 5test=# \! cat /tmp/test1.csvuser_id,user_name,age,gender,remark1,Jackie Chan,45,male,"""police story"",""project A"",""rush hour"""3,Brigitte Li,46,female,4,Maggie Cheung,39,female,5,Jet Li,41,male,"""Fist of Legend"",""Once Upon a Time in China"""2,Gong Li,38,female,"""Farewell My Concubine"",""Lifetimes Living"
test=# copy test to '/tmp/test1.csv' with csv header DELIMITER '|';COPY 5test=# \! cat /tmp/test1.csvuser_id|user_name|age|gender|remark1|Jackie Chan|45|male|"""police story"",""project A"",""rush hour"""3|Brigitte Li|46|female|4|Maggie Cheung|39|female|5|Jet Li|41|male|"""Fist of Legend"",""Once Upon a Time in China"""2|Gong Li|38|female|"""Farewell My Concubine"",""Lifetimes Living"
test=# copy test to '/tmp/test1.csv' with csv header null 'to be supplemented';COPY 5test=# \! cat /tmp/test1.csvuser_id,user_name,age,gender,remark1,Jackie Chan,45,male,"""police story"",""project A"",""rush hour"""3,Brigitte Li,46,female,to be supplemented4,Maggie Cheung,39,female,to be supplemented5,Jet Li,41,male,"""Fist of Legend"",""Once Upon a Time in China"""2,Gong Li,38,female,"""Farewell My Concubine"",""Lifetimes Living"