Received: from rush.u-netsys.com.br (rush.u-netsys.com.br [200.192.48.10]) by hub.org (8.10.1/8.10.1) with SMTP id e7PFBUI73386 for ; Fri, 25 Aug 2000 11:11:31 -0400 (EDT) Received: (qmail 19746 invoked from network); 25 Aug 2000 15:11:26 -0000 Received: from ppp35-pm3.u-netsys.com.br (HELO viafractal.com.br) (200.192.49.164) by rush.u-netsys.com.br with SMTP; 25 Aug 2000 15:11:26 -0000 Message-ID: <39A68D36.EADD6043@viafractal.com.br> Date: Fri, 25 Aug 2000 12:13:59 -0300 From: Renato De Giovanni X-Mailer: Mozilla 4.72 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: weird structure References: <200008241824.e7OIOR528066@hub.org> <39A5E7A4.E928FC2C@vpcit.ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200008/285 > > Consider the following tables/fields: > > table "person": fields "p_id", "p_name". > > table "person_attribute": fields "a_id", "a_name". > > table "person_data": fields "d_person_id", "d_attribute_id", > > "d_value". > > > > Also consider that a person may not have data related to all possible > > attributes. > > > > Using this structure, how could I retrieve in one row with a single > > select statement all attributes from a person (showing null to > > attributes that were not registered to him)? > > > > Thanks for any suggestion, > > -- > > Renato > > Sao Paulo - SP - Brasil > > rdg@viafractal.com.br > > I did similar things using the following technique: > in frontend I gather all attributes from person_attribute and then > generate a query like this: > > select *, (select distinct d_value from person_data where d_person_id = > person.p_id and > d_attribute_id = 'here first attribute id'), (select distinct d_value > from person_data where d_person_id = person.p_id and d_attribute_id = > 'here second attribute id'), ... from person > -- > Sincerely yours, > Yury Yury... That worked perfectly! Thank you very much! Tell me, I've never seen this sql construction before, is it specific to postgres? Or should it also work on other databases? And is there any relevant performance issue considering this kind of database schema and its peculiar sql commands? Thanks again! -- Renato Sao Paulo - SP - Brasil rdg@viafractal.com.br