gpt4 book ai didi

postgresql - 将文本内容导出到不带\n标记的文本文件

转载 作者:行者123 更新时间:2023-11-29 11:43:34 25 4
gpt4 key购买 nike

当我尝试导出字段的文本内容时,该内容具有回车符,这些字符的输出类似于\N 字符串。

例如:

create table foo ( txt text );
insert into foo ( txt ) values ( 'first line
second line
...
and other lines');
copy foo ( txt ) to '/tmp/foo.txt';

我要返回以下 (a):

first line
second line
...
and other lines

但是,输出是(b):

first line\Nsecond line\N...\Nand other lines

有人知道如何获得 (a) 输出吗?

最佳答案

\N 源于一行必须对应一个数据库行这一事实。

此规则对于 CSV 格式放宽,其中多行文本是可能的,但引号字符(默认情况下:")将包含文本。

如果你想要多行输出并且它周围没有封闭字符,你不应该使用 COPY 而应该使用 SELECT

假设一个unix shell作为调用者的执行环境,你可以这样做:

psql -A -t -d dbname -c 'select txt from foo' >/tmp/file.txt

关于postgresql - 将文本内容导出到不带\n标记的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13925021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com