![](/img/trans.png)
[英]pandas or postgres table - how to convert string currency values e.g. “£300k”
[英]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.