Sql 更新包含换行符的文本列'\n';
我遇到了PostgreSQL的奇怪行为,我尝试运行以下查询Sql 更新包含换行符的文本列'\n';,sql,postgresql,sql-update,psql,Sql,Postgresql,Sql Update,Psql,我遇到了PostgreSQL的奇怪行为,我尝试运行以下查询 update posts set content = replace(content, '\n', '<br>') where content is not null; 更新帖子 set content=replace(内容“\n”,“”) 内容不为空; 它对数据库中的数据没有任何作用。我**尝试手动提交(包括尝试从psql运行此查询)**以及将DBeaver/pgAdmin设置为自动提交,但没有成功 结果告诉我,3
update posts
set content = replace(content, '\n', '<br>')
where content is not null;
更新帖子
set content=replace(内容“\n”,“
”)
内容不为空;
它对数据库中的数据没有任何作用。我**尝试手动提交(包括尝试从psql运行此查询)**以及将DBeaver/pgAdmin设置为自动提交,但没有成功
结果告诉我,37行已更新,但更改不存在。如果我尝试提交,它会告诉我0行受影响
我根本没有触发器,所以这是不可能的
我在这里遗漏了什么吗?在文字前使用
e
:
update posts
set content = replace(content, e'\n', '<br>')
where content is not null
-- or better
-- where content like e'%\n%'
更新帖子
set content=replace(content,e'\n','
')
其中内容不为空
--或者更好
--其中包含像e“%\n%”这样的内容
从文档()中:
转义字符串常量是通过在开头单引号前写字母E(大写或小写)来指定的