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 285A1D1B2E0 for ; Thu, 5 Aug 2004 15:18:57 -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 48299-02 for ; Thu, 5 Aug 2004 18:18:53 +0000 (GMT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id DF269D1B252 for ; Thu, 5 Aug 2004 15:18:51 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 2075367; Thu, 05 Aug 2004 11:11:39 -0700 Message-ID: <41127A0B.5030807@joeconway.com> Date: Thu, 05 Aug 2004 11:18:51 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040510 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Caleb Simonyi-Gindele Cc: pgsql-sql@postgresql.org Subject: Re: contrib/tablefunc crosstab References: <000001c47b10$97178250$c201a8c0@borderveygqj37> In-Reply-To: <000001c47b10$97178250$c201a8c0@borderveygqj37> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/31 X-Sequence-Number: 18528 Caleb Simonyi-Gindele wrote: > My problem is that the rows are populated from right to left irrespective of > the column. So the $561.99 in vet1 actually belongs to vet2. There are never > any blank cells in the middle or start of a row - they always come at the > end. How do I get the amount for that date into the appropriate column? You either need to be sure there are no "gaps" in your source rows (provide one row for every category for each group, e.g. by doing an outer join) or use the hashed version of the function. Search the README for: crosstab(text source_sql, text category_sql) That is the hashed version that will do what you're looking for. HTH, Joe