更新包含换行符 '\n' 的文本列
Update a text column that contains a newline character '\n'
我在尝试 运行 以下查询时遇到 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.
我在尝试 运行 以下查询时遇到 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.