在 Postgres 中,我试图将一个字符串附加到单个字段中每行数据的末尾。
例如,我有以下名为personal_details的数据库表:
+-------+--------+-----------------------------------------------------+
| name | age | details |
+-------+--------+-----------------------------------------------------+
| Dave | 67 | This is some text made by Dave | <-- Note the next sentence is on the next line
| | | He is a dentist and works five days a week |
| | | | <-- Note there is a blank line between these two sentences
| | | He enjoys sports and loves burgers |
| | | He hates pizza |
+-------+--------+-----------------------------------------------------+
| Paul | 34 | This is some text from a different person |
| | | |
| | | Paul is always very happy |
| | | He loves dogs |
+-------+--------+-----------------------------------------------------+
| Lucy | 27 | Lucy is the only girl in this database table |
| | | She likes coffee |
| | | |
| | | She does karate at the weekend |
+-------+--------+-----------------------------------------------------+
问题(为了解释我的问题而大大简化):
我正在使用该personal_details
表创建一个personal_details_view
使用以下简单 SQL 调用的视图:
SELECT personal_details.name, personal_details.age, peronsal_details.details
FROM personal_details
但是在这个视图中,在上Details
表的字段中,我想根据是单换行还是双换行,在每个句子的末尾插入一个特定的字符串。
例如,在视图中Detail
,Dave、Paul 和 Lucy 的字段将变为:
---------------------------------------------------------
This is some text made by Dave</text></line><line><text> <-- to signify a SINGLE newline followed this
He is a dentist and works five days a week</text></line><line><text></text></line><line><text> <-- to signify a DOUBLE newline followed this
He enjoys sports and loves burgers</text></line><line><text>
He hates pizza
--------------------------------------------------------
---------------------------------------------------------
This is some text from a different person</text></line><line><text></text></line><line><text> <-- to signify a DOUBLE newline followed this
Paul is always very happy</text></line><line><text> <-- to signify a SINGLE newline followed this
He loves dogs
---------------------------------------------------------
---------------------------------------------------------
Lucy is the only girl in this database table</text></line><line><text> <-- to signify a SINGLE newline followed this
She likes coffee</text></line><line><text></text></line><line><text> <-- to signify a DOUBLE newline followed this
She does karate at the weekend
---------------------------------------------------------
</text></line><line><text>
表示这句话后面跟着一个新行
</text></line><line><text></text></line><line><text>
表示这句话后面有一个双新行。
我可能忽略了一种明显的方法,但我看不到这样做的合乎逻辑的方法。