If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > psql output to text file: how to output linebreaks between records?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-12, 05:50
martijnsenden martijnsenden is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Question psql output to text file: how to output linebreaks between records?

Hi All,

I have a psql command that outputs data to a textfile (on Windows):
Code:
psql -a -d somedb -h somehost -U someuser -c "select * from someschema.sometable;" -A -F ; -R \r\n -o "c:\somefile.txt"
Now this outputs the data with \r\n as a literal string in the text between each record. What I need is to have each record start on an actual new line, with a 'hard return' between them. Can this be achieved using psql from the command line?

Any help would be appreciated!

Best regards,
Martijn Senden.
Reply With Quote
  #2 (permalink)  
Old 01-03-12, 11:48
martijnsenden martijnsenden is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Smile Solved, but...

Hi All,

Well, sometimes solutions can be so easy you just overlook them. The default behaviour for psql is to use a newline (\n) between each record. This was fine for me, I just started using -R right from the start and couldn't find the right value. I'm still curious what it is though. I might be happier if I would be able to use a \r\n. I did read somewhere that on Linux you can do:
Code:
-R $'\r\n'
This doesn't work for windows though. If you have any ideas...

Best regards,
Martijn Senden.
Reply With Quote
Reply

Tags
linebreak, psql, text file

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On