Unix Technical Forum

Command line option

This is a discussion on Command line option within the pgsql Novice forums, part of the PostgreSQL category; --> Hi How do I write my psql command line if I want the output to be tab separated? If ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:51 PM
David
 
Posts: n/a
Default Command line option

Hi

How do I write my psql command line if I want the output to be tab
separated?

If I use psql interactively, I would go

#psql name_of_db

name_of_db =# \a
name_of_db =# \f '\t'
name_of_db =# \o outputfile.txt
name_of_db =# \i queryfile.sql

This produces nice tab separated output that I can open in Excel and
that is recognised as such.

I understand that my command line should look like this:

psql -A -F something_to_produce_a_tab -f queryfile.sql -o
outputfile.txt name_of_db

But obviously I am struggling to get the string for
something_to_produce_a_tab right. I tried '\t' of course and many
variants of it, but I always ending up inserting the string literally
(more or less).

Can somebody please help? I am on FreeBSD, using the bash shell and
PostgreSQL 8.1.2.

Thanks

DR

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:51 PM
John Purser
 
Posts: n/a
Default Re: Command line option

On Tue, 9 May 2006 00:28:45 +0100
David <davidr@talamh.org.uk> wrote:

> Hi
>
> How do I write my psql command line if I want the output to be tab
> separated?
>
> If I use psql interactively, I would go
>
> #psql name_of_db
>
> name_of_db =# \a
> name_of_db =# \f '\t'
> name_of_db =# \o outputfile.txt
> name_of_db =# \i queryfile.sql
>
> This produces nice tab separated output that I can open in Excel and
> that is recognised as such.
>
> I understand that my command line should look like this:
>
> psql -A -F something_to_produce_a_tab -f queryfile.sql -o
> outputfile.txt name_of_db
>
> But obviously I am struggling to get the string for
> something_to_produce_a_tab right. I tried '\t' of course and many
> variants of it, but I always ending up inserting the string
> literally (more or less).
>
> Can somebody please help? I am on FreeBSD, using the bash shell and
> PostgreSQL 8.1.2.
>
> Thanks
>
> DR
>
> ---------------------------(end of
> broadcast)--------------------------- TIP 9: In versions below 8.0,
> the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match


David,

Try using \pset fieldsep ’\t’ instead of the -F switch.

John Purser

--
.... A solemn, unsmiling, sanctimonious old iceberg who looked like he
was waiting for a vacancy in the Trinity.
-- Mark Twain

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:58 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com