gpt4 book ai didi

sql - 更新包含换行符的文本列 '\n'

转载 作者:行者123 更新时间:2023-11-29 12:48:59 24 4
gpt4 key购买 nike

我在尝试运行以下查询时遇到 PostgreSQL 的奇怪行为

update posts 
set content = replace(content, '\n', '<br>')
where content is not null;

而且它没有对数据库中的数据做任何事情。我 ** 尝试手动提交(包括尝试从 psql 运行此查询) ** 以及将 DBeaver/pgAdmin 设置为 AUTOCOMMIT 但无济于事。

结果告诉我已经更新了 37 行,但没有更改。如果我尝试提交,它会告诉我 0 行受影响。

我根本没有触发器,所以这是不可能的。

我是不是漏掉了什么?

最佳答案

在文字前使用e:

update posts 
set content = replace(content, e'\n', '<br>')
where content is not null
-- or better
-- where content like e'%\n%'

来自文档(String Constants with C-Style Escapes):

An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote.

关于sql - 更新包含换行符的文本列 '\n',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58359796/

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