Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id EB349174E987 for ; Fri, 24 Feb 2012 04:27:55 -0400 (AST) Received: from mail.scanlab.de ([62.138.55.241]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0qVM-0002Hu-69 for pgsql-sql@postgresql.org; Fri, 24 Feb 2012 08:27:54 +0000 Received: from unknown (HELO Exchange-Server.scanlab-intern.de) ([172.16.20.15]) by mail.scanlab-intern.de with ESMTP/TLS/AES128-SHA; 24 Feb 2012 09:27:39 +0100 Received: from Exchange-Server.scanlab-intern.de ([127.0.0.1]) by Exchange-Server ([127.0.0.1]) with mapi; Fri, 24 Feb 2012 09:27:39 +0100 From: Andreas Gaab To: "pgsql-sql@postgresql.org" Date: Fri, 24 Feb 2012 09:27:38 +0100 Subject: Re: crosstab help Thread-Topic: [SQL] crosstab help Thread-Index: AczyzAXoTLf+oz8eRI+JXxFE0WcmEQAAHWZg Message-ID: <48DA836F3865C54B8FBF424A3B775AF667451998F1@Exchange-Server> References: <2071893.Jsp6YpFfLm@linux-12> In-Reply-To: <2071893.Jsp6YpFfLm@linux-12> Accept-Language: de-DE Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: de-DE Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/78 X-Sequence-Number: 36371 Hi, the return type of the crosstab must be defined correctly, according to the= number of expected columns. Try following (untested): select * from crosstab( 'select item_number::text as row_name, to_char(week_of,''MM-DD-YY'')::date = as bucket, planned_qoh::integer as buckvalue from xchromasun._chromasun_tot= als(now()::date)') as ct(item_number text, week_of_1 date, week_of_2 date, week_of_3 date) Regards, Andreas -----Urspr=FCngliche Nachricht----- Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]= Im Auftrag von John Fabiani Gesendet: Freitag, 24. Februar 2012 09:11 An: pgsql-sql@postgresql.org Betreff: [SQL] crosstab help 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 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes = to your subscription: http://www.postgresql.org/mailpref/pgsql-sql