0

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上記の表のフィールドで、改行が 1 つまたは 2 つあるかどうかに応じて、各文の最後に特定の文字列を挿入したいと考えています。

たとえば、ビューでは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>この文に続いて二重の改行を意味します。

これを行うための明白な方法を見落としているかもしれませんが、これを行う論理的な方法がわかりません。

4

1 に答える 1