pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aram Fingal <fingal@multifactorial.com>
To: Postgres-General General <pgsql-general@postgresql.org>
Subject: Re: crosstab
Date: Tue, 4 Sep 2012 15:48:55 -0400
Message-ID: <09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com> (raw)
In-Reply-To: <504655DD.4030701@joeconway.com>
References: <1346773199616-5722632.post@n5.nabble.com>
	<1346784707.8977.6.camel@asus-1001PX.home>
	<73FF0C6A-965B-4456-BA90-2B8FD1CBC118@multifactorial.com>
	<504655DD.4030701@joeconway.com>


On Sep 4, 2012, at 3:26 PM, Joe Conway wrote:

> On 09/04/2012 12:17 PM, Aram Fingal wrote:
>> On Sep 4, 2012, at 2:51 PM, Vincent Veyron wrote:
>>> see the documentation for Additional Supplied Modules, in your
>>> case tablefunc :
>>> 
>>> http://www.postgresql.org/docs/9.1/static/tablefunc.html
>> 
>> I evaluated tablefunc about a year and a half ago and found that it
>> was not what I wanted because you have to explicitly list what you
>> want the columns to be.  In some cases, there will be hundreds of
>> columns in the pivoted table.  The Reshape library in R can pivot
>> tables without you even knowing ahead of time how many columns there
>> are going to be.
> 
> Sure, but you cannot return that reshaped table to postgres without
> specifying the list of columns explicitly. That is because of how
> postgres works internally and has nothing to do with whether you are
> using crosstab from tablefunc, PL/R, or some hand-coded SQL statement to
> build your crosstab.
> 
> But certainly if you can do all your work on the reshaped table within
> the R environment, PL/R will be easier to use.


So, are you saying that if I do something like this:

copy(crosstab(source_sql, category_sql)) to '/output.csv' with csv;

Then I don't have to list what the columns are going to be?  In other words, I can skip the "AS (...)" clause which is shown in the examples in the tablefunc documentation?

-Aram



view thread (25+ messages)  latest in thread

Message-ID: <09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com>
Permalink:  ../09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com/
Also on:    postgresql.org/message-id/09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: fingal@multifactorial.com
  Subject: Re: crosstab
  In-Reply-To: <09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com>
  References: <1346773199616-5722632.post@n5.nabble.com> <1346784707.8977.6.camel@asus-1001PX.home> <73FF0C6A-965B-4456-BA90-2B8FD1CBC118@multifactorial.com> <504655DD.4030701@joeconway.com> <09AE4623-B1E5-4F8D-AC55-EF5906A6411C@multifactorial.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox