强制给某个列添加引用字符
最近更新时间: 2025-02-18 16:02:00
postgres=# copy t to '/data/pgxz/t.txt' (format 'csv',force_quote (f1,f2));
COPY 3
postgres=# \! cat /data/pgxz/t.txt
"1","TDSQL PG",,7
"2","pg'"", xc%",2017-10-28 18:24:05.643102,3
"3","pgxz",2017-10-28 18:24:05.645691,
#指定2列强制添加引用字符
postgres=# copy t to '/data/pgxz/t.txt' (format 'csv',force_quote (f1,f4,f3,f2));
COPY 3
postgres=# \! cat /data/pgxz/t.txt
"1","TDSQL PG",,"7"
"2","pg'"", xc%","2017-10-28 18:24:05.643102","3"
"3","pgxz","2017-10-28 18:24:05.645691",
#指定4列强制添加引用字符,字段的顺序可以任意排列
postgres=# copy t to '/data/pgxz/t.txt' (format 'text',force_quote (f1,f2,f3,f4));
ERROR: COPY force quote available only in CSV mode
postgres=#
#只有使用CSV格式时才允许这个选项。