繁体   English   中英

Postgres“转义字符串常量”(例如E'foo \\ nbar')不适用于psql \\ copy

[英]Postgres “escape string constant” (e.g. E'foo\nbar') doesn't work with psql \copy

我使用转义字符串常量psql执行以下查询:

psql=# select E'foo\nbar' as example;

导致:

 example
---------
 foo    +
 bar
(1 row)

我使用\\copy查询输出写入文件:

psql=# \copy (select * from (select E'foo\nbar') as q) to 'test.txt'
COPY 1

并检查结果:

bash$ cat test.txt
foo\nbar

但我期望的输出是:

foo
bar

我怎样才能像预期的那样得到\\copy用文字换行符替换\\n 或者,还有什么其他方法可以得到我想要的结果?

一种解决方法是在命令行上使用Postgres COPY指令(不要与psql的\\copy meta-command混淆):

psql -h myhost -d mydatabase -c "COPY (select E'foo\nbar') TO STDOUT WITH CSV"
"foo
bar"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM