在更新文本字段时在postgresql中插入换行符 [英] Insert line break in postgresql when updating text field

查看:3735
本文介绍了在更新文本字段时在postgresql中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更新我的postgresql数据库表中的文本字段。

I am trying to update a text field in a table of my postgresql database.

UPDATE public.table SET long_text = 'First Line' + CHAR(10) + 'Second line.' WHERE id = 19;

我的预期结果是单元格将如下所示:

My intended result is that the cell will look like this:


First Line
Second line

上述语法返回错误。

推荐答案

您想要 chr(10) c> char(10)。

You want chr(10) instead of char(10).

小心这个,因为这可能是错误的换行符。 右换行符取决于消费它的客户端。 Mac,Windows和Linux都使用不同的换行符。浏览器会期待< br />

Be careful with this, because that might be the wrong newline. The "right" newline depends on the client that consumes it. Macs, Windows, and Linux all use different newlines. A browser will expect <br />.

PostgreSQL 9.1+。但请阅读以下链接的文档。

It might be safest to write your update like this for PostgreSQL 9.1+. But read the docs linked below.

UPDATE public.table 
SET long_text = E'First Line\nSecond line.' 
WHERE id = 19;

默认值'standard_conforming_strings 在9.1+中为开启。

The default value of 'standard_conforming_strings' is 'on' in 9.1+.

show standard_conforming_strings;

这篇关于在更新文本字段时在postgresql中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆