Re: How to insert a carriage return and line field between fields in a query

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: How to insert a carriage return and line field between fields in a query
Date: 2015-07-09 23:18:49
Message-ID: CAKFQuwbWV6n9Oa8C6EdOXdzwtGSLBhJ=q1dVDcyP79ixAwbLEQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thursday, July 9, 2015, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> wrote:

> I have a query like the following:
>
> SELECT fld1 || fld2
>
> I need to insert a carriage return (\r) and a line feed (\n) after each
> field. How can I do this?
>
> I tried
> SELECT fld1 || \r\n || fld2 || \r\n
> and also
> SELECT fld1 || '\r\n' || fld2 || '\r\n'
>
> without success.
>
> I will very much appreciate your feedback.
>

SELECT fld1 || E'\r\n' || fld2

The E tells Postgresql to interpret backslash escapes within the string.

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alex Ignatov 2015-07-15 14:10:18 User defined exceptions
Previous Message JORGE MALDONADO 2015-07-09 23:10:19 How to insert a carriage return and line field between fields in a query