X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D0A1B5288E for ; Wed, 1 Jun 2005 11:14:46 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21270-02 for ; Wed, 1 Jun 2005 14:14:43 +0000 (GMT) Received: from ms0.math.ucalgary.ca (ms0.math.ucalgary.ca [136.159.61.8]) by svr1.postgresql.org (Postfix) with ESMTP id CA23F52872 for ; Wed, 1 Jun 2005 11:14:32 -0300 (ADT) Received: from [136.159.61.64] (linuxtest.math.ucalgary.ca [136.159.61.64]) by ms0.math.ucalgary.ca (8.12.10+Sun/8.12.10) with ESMTP id j51EEVXb013596 for ; Wed, 1 Jun 2005 08:14:31 -0600 (MDT) Subject: Returning a Cross Tab record set from a function From: Marc Wrubleski To: pgsql-sql@postgresql.org Content-Type: text/plain Message-Id: <1117635270.12213.49.camel@linuxtest.math.ucalgary.ca> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 01 Jun 2005 08:14:31 -0600 Content-Transfer-Encoding: 7bit X-Math-Stat-MailScanner-Information: Please contact the ISP at 220 3944 for more information X-Math-Stat-MailScanner: Found to be clean X-Math-Stat-MailScanner-From: mlwruble@math.ucalgary.ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/68 X-Sequence-Number: 21669 I have read the great work that all the list members have done working with cross tabs (pivot tables) in postgresql. The issue I have not seen a solution for, but would really like to see, is the ability to return the results of a dynamic (variable # of columns) cross tab function as a recordset. The excellent code contributed by Christoph Haller in the "Generating a cross tab II (pivot table)" thread was very useful, but it dumps the results into a view. I need to query like "select * from create_pivot_report('sales_report2','vendor','product','sales','sum','sales');" and have the result back as a recordset. The reason I want to do this is that I have a hierarchical structure of itemtypes where each itemtype contains an arbitrary number of items, AND each itemtype has an arbitrary number of attributes. I want to perform the crosstab on the items with attributes for a given itemtype. The static code works perfectly fine for a query of an itemtype, BUT the itemtypes and attributes may change often enough that creating views for each itemtype will be insufficient. It seems I can do this from any higher level language, but it drives me crazy that I can't perform this operation as a function inside of Postgres... Thanks for any thoughts you might have... -- Marc Wrubleski