Re: dynamic crosstab

From: Balázs Klein <bklein(at)t-online(dot)hu>
To: "'Reece Hart'" <reece(at)harts(dot)net>, "'Tino Wildenhain'" <tino(at)wildenhain(dot)de>
Cc: "'SunWuKung'" <Balazs(dot)Klein(at)t-online(dot)hu>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: dynamic crosstab
Date: 2008-02-14 08:10:36
Message-ID: 20080214081036.6A1042E3C2@mail01d.mail.t-online.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, once I have the select outputting it to CSV is not a problem. As you say PG handles that nicely.

Thx
SWK

-----Original Message-----
From: Reece Hart [mailto:reece(at)harts(dot)net]
Sent: Wednesday, February 13, 2008 9:39 PM
To: Tino Wildenhain
Cc: SunWuKung; pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] dynamic crosstab

On Wed, 2008-02-13 at 14:04 +0100, Tino Wildenhain wrote:
> Well after all you want a CSV not a table. You could shortcut this
> with a generic query which creates array out of your "columns"
> and join them to a CSV line. This would just be outputted as
> one single column from database.

Depending on your use case, this may be a better way:

In psql:
=> \copy (select col1,col2,col3 from data) TO data.csv CSV HEADER

or on the command line:
$ psql -c '\copy (select col1,col2,col3 from data) TO data.csv CSV HEADER'

Strictly speaking, the CSV formatting isn't being done in the database
but rather by psql.

-Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Emil J. 2008-02-14 11:44:06 Re: pg_dump, pg_restore.
Previous Message Balázs Klein 2008-02-14 08:04:09 Re: dynamic crosstab