Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 0C489174E987 for ; Fri, 24 Feb 2012 04:12:03 -0400 (AST) Received: from [76.14.161.106] (helo=newserver.jfcomputer.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0qG0-00022V-34 for pgsql-sql@postgresql.org; Fri, 24 Feb 2012 08:12:03 +0000 Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 4F5A912348 for ; Fri, 24 Feb 2012 08:11:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V1I8FsUZjXJY for ; Fri, 24 Feb 2012 00:11:40 -0800 (PST) Received: from linux-12.localnet (unknown [192.168.1.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id A8E47D90 for ; Fri, 24 Feb 2012 00:11:40 -0800 (PST) From: John Fabiani To: pgsql-sql@postgresql.org Subject: crosstab help Date: Fri, 24 Feb 2012 00:11:28 -0800 Message-ID: <2071893.Jsp6YpFfLm@linux-12> User-Agent: KMail/4.7.2 (Linux/3.1.9-1.4-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Host-Lookup-Failed: Reverse DNS lookup failed for 76.14.161.106 (failed) X-Pg-Spam-Score: 1.6 (+) X-Archive-Number: 201202/77 X-Sequence-Number: 36370 I have a simple table item_number week_of planned_qoh ------------------ ------------------ ------------------ 00005 2012-02-05 30 00005 2012-02-12 40 00005 2012-02-19 50 where item_number text week_of date planned_qoh integer I have a function that returns the table as above: chromasun._chromasun_totals(now()::date) I want to see 00005 2012-02-05 2012-02-12 2012-02-19 30 40 50 This is what I have tried (although, I have tired many others) select * from crosstab('select item_number::text as row_name, to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as buckvalue from xchromasun._chromasun_totals(now()::date)') as ct(item_number text, week_of date, planned_qoh integer) I get ERROR: return and sql tuple descriptions are incompatible What am I doing wrong? Johnf