pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Renato De Giovanni <rdg@viafractal.com.br>
To: pgsql-sql@postgresql.org
Subject: Re: weird structure
Date: Fri, 25 Aug 2000 12:13:59 -0300
Message-ID: <39A68D36.EADD6043@viafractal.com.br> (raw)
References: <200008241824.e7OIOR528066@hub.org>
	<39A5E7A4.E928FC2C@vpcit.ru>

> > 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






view thread (6+ messages)  latest in thread

Message-ID: <39A68D36.EADD6043@viafractal.com.br>
Permalink:  ../39A68D36.EADD6043@viafractal.com.br/
Also on:    postgresql.org/message-id/39A68D36.EADD6043@viafractal.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: rdg@viafractal.com.br
  Subject: Re: weird structure
  In-Reply-To: <39A68D36.EADD6043@viafractal.com.br>
  References: <200008241824.e7OIOR528066@hub.org> <39A5E7A4.E928FC2C@vpcit.ru> <39A68D36.EADD6043@viafractal.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox