Received: from merganser.its.uu.se (merganser.its.uu.se [130.238.6.236]) by hub.org (8.9.3/8.9.3) with ESMTP id TAA10233 for ; Wed, 8 Dec 1999 19:13:56 -0500 (EST) (envelope-from peter@localhost.its.uu.se) Received: from regulus.its.uu.se ([130.238.7.19]:63022 "EHLO regulus.its.uu.se") by merganser.its.uu.se with ESMTP id ; Thu, 9 Dec 1999 01:13:32 +0100 Received: from peter (helo=localhost) by regulus.its.uu.se with local-esmtp (Exim 3.02 #2) id 11vrIC-0003Yb-00; Thu, 09 Dec 1999 01:18:44 +0100 Date: Thu, 9 Dec 1999 01:18:44 +0100 (CET) From: Peter Eisentraut To: Thilo Mezger cc: pgsql-sql@postgresql.org Subject: Re: [SQL] turning a table by 90 degrees In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: Peter Eisentraut On 1999-12-08, Thilo Mezger mentioned: > hi, > > i've got a table like this (plus a primary key and some other fields): > > key | value | custid > ---------+---------+--------- > name | peter | 2 > age | 123 | 2 > foo | bar | 2 > [...] | | > name | john | 3 > [...] > > you can think of a table which is turned by 90 degrees. this can be > quite useful when you don't know in advance what key/values pairs you > have to store. > > now it would be nice to find a query which returns this result for > custid=2: > > name | age | foo > ------+-----+------ > peter | 123 | bar I don't see why a table SELECT * FROM your_table WHERE custid = 2; would be any different. Just switch the column and row addressing logic in your application. key | value | custid ---------+---------+--------- name | peter | 2 age | 123 | 2 foo | bar | 2 There's really no way to do what you suggested. -- Peter Eisentraut Sernanders väg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden