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 64D6E5667D for ; Tue, 22 Mar 2005 00:39:35 +0000 (GMT) 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 60766-05 for ; Tue, 22 Mar 2005 00:39:20 +0000 (GMT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 5AB36565AD for ; Tue, 22 Mar 2005 00:39:15 +0000 (GMT) Received: from mail48-s.fg.online.no (mail48-s.fg.online.no [148.122.161.48]) by svr4.postgresql.org (Postfix) with ESMTP id 2D9845AFAA2 for ; Mon, 21 Mar 2005 22:42:49 +0000 (GMT) Received: from [192.168.0.57] (062016240144.customer.alfanett.no [62.16.240.144]) by mail48.fg.online.no (8.12.11/8.12.11) with ESMTP id j2LMb85T008358 for ; Mon, 21 Mar 2005 23:37:09 +0100 (CET) From: "Leif B. Kristensen" To: pgsql-sql@postgresql.org Subject: Re: "Flattening" query result into columns Date: Mon, 21 Mar 2005 23:37:08 +0100 User-Agent: KMail/1.7.2 References: <20050321215723.E79E356388@svr1.postgresql.org> In-Reply-To: <20050321215723.E79E356388@svr1.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200503212337.08682.leif@solumslekt.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.139 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/293 X-Sequence-Number: 20772 On Monday 21 March 2005 22:57, Thomas Borg Salling wrote: > I am looking for a way to "flatten" a query result, so that rows are > "transposed" into columns, just as asked here for oracle: > > Is there any way to do this with pgsql =A0? Just to help out the guys, here's a working link: What you're asking for is called a pivot table, and at least in Oracle=20 they use a function called decode(). I need exactly the same thing, but=20 I too am unable to find the optimal way to do it in PostgreSQL. =2D-=20 Leif Biberg Kristensen http://solumslekt.org/