Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux