Thread: psql record separator

psql record separator

From
Charley Tiggs
Date:
I'm trying to create a CRLF record separator using the following syntax:

psql -R "\r\n" dbname username -c "select * from foo" > data_file.txt

But, no matter what I do, it only outputs a newline (\n).  How can I
force the separator to be a windows line break (CRLF)?

Charley

Re: psql record separator

From
Tom Lane
Date:
Charley Tiggs <lists@tiggs.net> writes:
> I'm trying to create a CRLF record separator using the following syntax:
> psql -R "\r\n" dbname username -c "select * from foo" > data_file.txt

> But, no matter what I do, it only outputs a newline (\n).  How can I
> force the separator to be a windows line break (CRLF)?

According to the code, -R only affects the output in "unaligned" output
mode.  Can you use that?

            regards, tom lane

Re: psql record separator

From
Charley Tiggs
Date:
Tom Lane wrote:
> Charley Tiggs <lists@tiggs.net> writes:
>> I'm trying to create a CRLF record separator using the following syntax:
>> psql -R "\r\n" dbname username -c "select * from foo" > data_file.txt
>
>> But, no matter what I do, it only outputs a newline (\n).  How can I
>> force the separator to be a windows line break (CRLF)?
>
> According to the code, -R only affects the output in "unaligned" output
> mode.  Can you use that?

I added the "-A" switch and it output the string "\r\n" instead of an
actual CRLF.

psql -A -R "\r\n" -t dbname username -c "select * from foo" > data_file.txt

Charley

Re: psql record separator

From
"Andrej Ricnik-Bay"
Date:
On 10/01/2008, Charley Tiggs <lists@tiggs.net> wrote:

> I added the "-A" switch and it output the string "\r\n" instead of an
> actual CRLF.
>
> psql -A -R "\r\n" -t dbname username -c "select * from foo" > data_file.txt
I can't tell you what the proper incantation is (I didn't manage to get
it to play nice within 10 minutes), but how about a hackish solution like:
psql -A -t dbname username -c "select * from foo"|todos > data_file.txt

> Charley
Cheers,
Andrej



--
Please don't top post, and don't use HTML e-Mail :}  Make your quotes concise.

http://www.american.edu/econ/notes/htmlmail.htm

Re: psql record separator

From
Charley Tiggs
Date:
Andrej Ricnik-Bay wrote:
> On 10/01/2008, Charley Tiggs <lists@tiggs.net> wrote:
>
>> I added the "-A" switch and it output the string "\r\n" instead of an
>> actual CRLF.
>>
>> psql -A -R "\r\n" -t dbname username -c "select * from foo" > data_file.txt
> I can't tell you what the proper incantation is (I didn't manage to get
> it to play nice within 10 minutes), but how about a hackish solution like:
> psql -A -t dbname username -c "select * from foo"|todos > data_file.txt

I got it to work by using the actual character surrounded by quotes.
That's not ideal but at least I got the line endings I needed.

Charley