我在尝试运行以下查询时遇到 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/