From: | Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr> |
---|---|
To: | David Johnston <polobo(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [PG9.1] CTE usage |
Date: | 2013-09-16 15:48:03 |
Message-ID: | 1379346483.2424.12.camel@asus-1001PX.home |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Le lundi 16 septembre 2013 à 08:30 -0700, David Johnston a écrit :
> Ladislav Lenart wrote
> > Hello all.
> >
> > I am curious about the following usage of CTEs:
> >
> > Imagine three tables:
> > * item (id, item_type1_id, item_type2_id, ...)
> > * item_type1 (id, ...)
> > * item_type2 (id, ...)
> > where
> > * item_type1_id is FK to item_type1 (id)
> > * item_type2_id is FK to item_type2 (id)
>
> The mental model that comes to mind is:
>
> item (item_id)
> item_type1 (type1_id, item_id <FK>)
> item_type2 (type2_id, item_id <FK>)
>
> Or even better:
>
> item (item_id <PK>)
> item_type1 (item_id <PK; FK>)
>
> item_type2 (item_id <PK; FK>)
>
I would suggest :
item (item_id <PK>, id_type integer)
item_type1 (item_id <PK; FK>)
item_type2 (item_id <PK; FK>)
where item.id_type is either type_1 or type_2
So that the application knows which table to use?
But chances are the OP can't change his model easily.
--
Salutations, Vincent Veyron
http://marica.fr/
Gestion des contentieux juridiques, des sinistres d'assurance et des contrats
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Janes | 2013-09-16 16:32:18 | Re: Segmentation fault: pg_upgrade 9.1 to 9.3: pg_dump: row number 0 is out of range 0..-1 |
Previous Message | Ladislav Lenart | 2013-09-16 15:47:22 | Re: [PG9.1] CTE usage |