Re: A few questions about carriage returns (\r)

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jon Lapham <lapham(at)jandr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: A few questions about carriage returns (\r)
Date: 2006-06-15 15:19:11
Message-ID: 20060615151911.GF23567@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 15, 2006 at 11:51:21AM -0300, Jon Lapham wrote:
> So, as I understand it (please correct me if I'm wrong), UNIX uses a
> "newline" (or \n), Mac uses "carriage return" (or \r) and Win/DOS uses
> \r\n.

Correct.

> 1) Does anyone know why the "id" column is not visible for the final
> select statement? I guess a lone \r literally means to go to the
> farthest position to the left... but it seems like a bug that it moves
> past its column position. Bug in psql?

Well, your terminal moving the cursor left when it sees a \r, psql
isn't doing anything (which is the problem).

CVS HEAD contains patches that display the output more clearly.

> =======================
> 2) Is there a way to *view* the \n and \rs embedded in a TEXT field
> using psql?

You could use replace to make them visible.

> =======================
> 3) Is there a string function that is capable of replacing \r\n with \n?

Yes, replace.
# select replace('aac','a','b');
replace
---------
bbc
(1 row)

So replace(str, '\r', '\\r') should work

> More generally, is there a string function capable of regular
> expression replace? (eg: perl and other languages have "=~
> s/\r\n/\n/"). I imagine an SQL function that would work like this
> fictional function:

I beleive there is a regexp_replace. In psql, if you type \df you get a
list of all defined functions. The docs have info too.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jon Lapham 2006-06-15 15:35:02 Re: A few questions about carriage returns (\r)
Previous Message Jon Lapham 2006-06-15 14:51:21 A few questions about carriage returns (\r)