Skip site navigation (1) Skip section navigation (2)

Re: dumping query results to a csv

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Adi Alurkar <adi(at)sf(dot)net>
Cc: David Durham <ddurham(at)vailsys(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: dumping query results to a csv
Date: 2005-08-25 23:04:38
Message-ID: 20050825230438.GB11282@pervasive.com (view raw or flat)
Thread:
Lists: pgsql-admin
On Thu, Aug 25, 2005 at 03:48:54PM -0700, Adi Alurkar wrote:
> Greetings,
> 
> There is no direct way to achieve what you want, the easiest hack is  
> to create a temp table with you query i.e.
> 
> create table tmp_foo as select col1, col4, col7 from table1, table2  
> where  ....;
> copy table tmp_foo to [stdout|<file_name>]

Can we make this a TODO? It would certainly be handy to be able to COPY
directly from a query.

In the mean time, you can also do something like

SELECT field1 || ',' || field2 || ',' || field3

and capture the output of that to a file, but that's an uglier hack than
the temptable trick.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby(at)pervasive(dot)com
Pervasive Software        http://pervasive.com        512-569-9461

In response to

pgsql-admin by date

Next:From: Colin E. FreasDate: 2005-08-25 23:31:54
Subject: pgcrypto 'cryptsrc' in Makefile: what is that?
Previous:From: Jeff FrostDate: 2005-08-25 23:02:53
Subject: Re: dumping query results to a csv

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group