是\n
换行,不为空。如果您使用默认 tsv 模式 - 每个新行都表示为\n
区分新行和新行之间的差异,例如:
t=# copy(select query_to_xml('select datname,null blah from pg_database limit 2',false,true,'')) to stdout;
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <datname>postgres</datname>\n</row>\n\n<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <datname>t</datname>\n</row>\n\n
所以简单的 csv 选项会拯救你,例如:
t=# copy(select query_to_xml('select datname,null blah from pg_database limit 2',false,true,'')) to stdout csv;
"<row xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<datname>postgres</datname>
</row>
<row xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<datname>t</datname>
</row>
"
https://www.postgresql.org/docs/current/static/sql-copy.html
COPY TO 将使用 Unix 样式的换行符 (“\n”) 终止每一行。
等等...
更新
复制到标准输出或文件无关紧要:
t=# copy(select query_to_xml('select datname,null blah from pg_database limit 2',false,true,'')) to '/tmp/sp.xml' csv;
COPY 1
Time: 0.481 ms
t=# \! cat /tmp/sp.xml
"<row xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<datname>postgres</datname>
</row>
<row xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<datname>t</datname>
</row>
"