Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T8z8s-0000cl-67 for pgsql-general@postgresql.org; Tue, 04 Sep 2012 19:50:34 +0000 Received: from vm-emlprdomr-11.its.yale.edu ([130.132.50.177]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T8z8o-0000jW-9n for pgsql-general@postgresql.org; Tue, 04 Sep 2012 19:50:32 +0000 Received: from plattjt.med.yale.edu (plattjt.med.yale.edu [130.132.88.91]) by vm-emlprdomr-11.its.yale.edu (8.14.4/8.14.4) with ESMTP id q84JoN30020296 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Tue, 4 Sep 2012 15:50:26 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: crosstab From: Aram Fingal In-Reply-To: <504655DD.4030701@joeconway.com> Date: Tue, 4 Sep 2012 15:48:55 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <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> To: Postgres-General General X-Mailer: Apple Mail (2.1084) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.177 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/97 X-Sequence-Number: 190113 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 : >>>=20 >>> http://www.postgresql.org/docs/9.1/static/tablefunc.html >>=20 >> 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. >=20 > 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. >=20 > 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=