Search Postgresql Archives

Re: Exporting postgres query to CSV

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

 



On Tue, 09 May 2006 10:58:07 -0400
Ryan Suarez <ryan.suarez@xxxxxxxxxxxxxxx> wrote:

> Greetings,
> 
> I am running postgres 7.4.7 on debian sarge. 
> 
> I need to run an SQL query and store the results in a file.  The
> format needs to be comma separated values (CSV), so I can import this
> later in Excel.
> 
> Any ideas on how to accomplish this?
> 
> much appreciated,
> Ryan
> 
> 
> ---------------------------(end of
> broadcast)--------------------------- TIP 6: explain analyze is your
> friend

Ryan,

Two tips.

First:
psql -U <PGSQL USER> -o <OUPUT FILE NAME> --pset format=unaligned
--pset fieldsep=',' -c '<SQL COMMAND HERE>' -d <DATABASE NAME HERE>

I think that will give you the output you were after assuming you're
scripting psql and that you replace the values in <> with appropriate
values. The syntax is slightly different from the psql command line.

Second:
man psql is your friend.

John Purser



[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