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

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: A few questions about carriage returns (\r)
Дата
Msg-id 20060615151911.GF23567@svana.org
обсуждение исходный текст
Ответ на A few questions about carriage returns (\r)  (Jon Lapham <lapham@jandr.org>)
Ответы Re: A few questions about carriage returns (\r)  (Nis Jorgensen <nis@superlativ.dk>)
Re: A few questions about carriage returns (\r)  (Jon Lapham <lapham@jandr.org>)
Список 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Jon Lapham
Дата:
Сообщение: A few questions about carriage returns (\r)
Следующее
От: Nis Jorgensen
Дата:
Сообщение: Re: A few questions about carriage returns (\r)