X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 35D67D1B4E3 for ; Thu, 9 Oct 2003 13:15:54 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 21635-05 for ; Thu, 9 Oct 2003 10:15:07 -0300 (ADT) Received: from bzzagent.com (bzzagent.com [65.61.161.28]) by svr1.postgresql.org (Postfix) with SMTP id A336ED1B4F4 for ; Thu, 9 Oct 2003 10:15:03 -0300 (ADT) Received: (qmail 7868 invoked from network); 9 Oct 2003 13:21:19 -0000 Received: from pool-64-223-176-116.man.east.verizon.net (HELO hotdogrecords.com) (kurt@64.223.176.116) by bzzagent.com with SMTP; 9 Oct 2003 13:21:19 -0000 Message-ID: <3F855F38.9070803@hotdogrecords.com> Date: Thu, 09 Oct 2003 09:14:32 -0400 From: Kurt Overberg User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Selecting rows as if they were columns? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/101 X-Sequence-Number: 15501 Gang, I've got what I think should be a pretty simple problem- I just can't figure out how I'd do it. Heck, I can't even figure out how I'd search for an answer to this problem. I've got 2 tables: member and member_attr Member is just a standard entry for a member. Very simple: table member { id integer, name character varying(30) } Member_attr is just a table of name/value pairs, such as: table memberextra { memberid integer, param1 character varying(512), param2 character varying(512), } where param1 is the name, param2 is the value. Right now, I can: select member.id, member.name, member_attr.param1, member_attr.param2 from member, member_attr where member.id = member_attr.memberid; ...this gives me n rows per member where n = # of attributes for that member, like this: id | name | param1 | param2 ======================================= 1 | dave | home | /home/dave 1 | dave | testing | 1 2 | john | home | /home/john ...is there some way to make this return like this: id | name | home | testing ====================================== 1 | dave | /home/dave | 1 2 | john | /home/john | ...where it sort of "expands" the rows out into columns? Am I just going about this the wrong way? Thoughts on the subject would be greatly appreciated. thanks! /kurt