Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T8zfH-0003MY-GB for pgsql-general@postgresql.org; Tue, 04 Sep 2012 20:24:03 +0000 Received: from vm-emlprdomr-12.its.yale.edu ([130.132.50.178]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T8zfE-0003kJ-Ju for pgsql-general@postgresql.org; Tue, 04 Sep 2012 20:24:01 +0000 Received: from plattjt.med.yale.edu (plattjt.med.yale.edu [130.132.88.91]) by vm-emlprdomr-12.its.yale.edu (8.14.4/8.14.4) with ESMTP id q84KNx9e000483 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Tue, 4 Sep 2012 16:23:59 -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: <50465CD9.3050809@joeconway.com> Date: Tue, 4 Sep 2012 16:23:55 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: 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> <50465CD9.3050809@joeconway.com> To: Postgres-General General X-Mailer: Apple Mail (2.1084) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.178 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/101 X-Sequence-Number: 190117 On Sep 4, 2012, at 3:56 PM, Joe Conway wrote: > On 09/04/2012 12:48 PM, Aram Fingal wrote: >> So, are you saying that if I do something like this: >>=20 >> copy(crosstab(source_sql, category_sql)) to '/output.csv' with csv; >>=20 >> 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? >=20 > No, sorry, but that is not what I'm saying :-( >=20 > Wen you run >=20 > copy ("some query") to ... >=20 > it still requires postgres to execute "some query" and the standard > grammar rules will be applied. Postgres must be able to resolve data > types for the columns in the result, and therefore it needs you to > provide a column definition either at function creation time (via OUT > params or by explicit composite return type) or at execution time via > AS(...) clause. So then, PL/R is not a solution to being able to pivot tables directly = in PostgreSQL but I might be able to define a PL/R procedure which, for = example, pivots tables and then uses the write.table() function of R to = send the results to disk without returning any rows to PostgreSQL? Such = a procedure might prove be faster and more convenient than extracting = the data from PostgreSQL into an R application layer and then writing to = disk.=20 -Aram=