Skip site navigation (1) Skip section navigation (2)

Re: weird structure

From: Renato De Giovanni <rdg(at)viafractal(dot)com(dot)br>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: weird structure
Date: 2000-08-25 15:13:59
Message-ID: 39A68D36.EADD6043@viafractal.com.br (view raw or flat)
Thread:
Lists: pgsql-sql
> > 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(at)viafractal(dot)com(dot)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(at)viafractal(dot)com(dot)br




In response to

Responses

pgsql-sql by date

Next:From: hlefebvreDate: 2000-08-25 15:22:26
Subject: Re: Re: Date of creation and of change
Previous:From: Andreas TilleDate: 2000-08-25 14:59:59
Subject: Re: Date of creation and of change

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group