Postgres“转义字符串常量”(例如E'foo \ nbar')不能与psql \ copy一起使用

时间:2016-01-04 16:13:06

标签: postgresql psql string-interpolation

我使用escape string constant在<{1}}执行以下查询:

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? 或者,有什么其他方法可以得到我想要的结果?

1 个答案:

答案 0 :(得分:0)

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

\copy
相关问题