Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 4AEE363305F for ; Thu, 11 Jun 2009 04:53:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 25603-04 for ; Thu, 11 Jun 2009 04:53:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by mail.postgresql.org (Postfix) with ESMTP id A843F632637 for ; Thu, 11 Jun 2009 04:53:44 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MKv5w-1MEf6T43iT-0000nU; Thu, 11 Jun 2009 09:53:42 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1MEf6T-0007hh-00 for pgsql-sql@postgresql.org; Thu, 11 Jun 2009 09:53:41 +0200 Date: Thu, 11 Jun 2009 09:53:41 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: dynamic columns in a query Message-ID: <20090611075341.GC16593@a-kretschmer.de> References: <200906100519.34171.jfabiani@yolo.com> <000001c9ea68$217cb890$647629b0$@com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000001c9ea68$217cb890$647629b0$@com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX18i6tyx/f2Vt2c9TtSPMO8YvHihuOMh3GibXf8 tS2fVYPXMBpPjE9slJQN7kfdblmqiBl5U51MEZBsa+j7L0/Ax/ PE8YYw0z2rGyMtFiOOPbA== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.035 tagged_above=0 required=5 tests=AWL=0.035 X-Spam-Level: X-Archive-Number: 200906/52 X-Sequence-Number: 32657 In response to Jyoti Seth : > Hi All, > > Is there any way in postgres to write a query to display the result in > matrix form. (where column names are dynamic) > > For eg. > > > Employee Name Client1 Client2 Client3 Client4 > Emp1 100 102 90 23 > Emp2 56 0 23 98 > Emp3 34 45 76 0 > > > Here Client1, Client2... are the values from the database. There is a contrib-modul, tablefunc. It contains a crosstab-function. Maybe this can help you. Other solution: write a function in plpgsql and build a string that contains your query, and EXECUTE that string. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net