From: | Perry Smith <pedz(at)easesoftware(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
Cc: | Nis Jørgensen <nis(at)superlativ(dot)dk>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Foreign key constraint question |
Date: | 2007-07-22 19:01:23 |
Message-ID: | F88EE75D-B119-4D1F-9B92-C6F10C4A2B21@easesoftware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jul 22, 2007, at 10:35 AM, Alvaro Herrera wrote:
> Nis Jørgensen wrote:
>> Alvaro Herrera skrev:
>>> Nis Jørgensen wrote:
>>>
>>>> What if, for instance, I want to render a list of shapes?
>>>>
>>>> To render the shape, I need to get its data, to get its data, I
>>>> need to know what type it is. ISTM that the easiest way to achieve
>>>> this is storing the type info at the "top" of the table hierarchy.
>>>
>>> Try adding "tableoid" to the list of columns retrieved. Even
>>> better,
>>> cast that to regclass.
>>
>> This is if I use PG table inheritance, right?
>
> Right, that was what I was thinking.
Right now, I am pretty happy with what I have (but I do have some
extra data).
In what I call my item_base table, I have an item_id and item_type
(integer and string). The type is not the table name but a Class
name. I also have a table that goes from one to the other.
In each of my child (sub-class) tables I have the same tuple. But,
for example, in the companies table, I have an added constraint that
it is set to "Company". I have a "initially deferred" foreign
constraint of item_id and item_type from the child tables to the
item_base table. The item_base table has a check constraint that
translates the item_type to a table name and then verifies that the
id in the referenced table exists. I also have "on delete cascade"
set so they both disappear at the same time.
I do not have item_id in the item_base table of type serial. Instead
I have a sequence number that the child tables get their id from (all
from the same sequence). Then this id is put into the item_base
table. This is because the child table entry must be created first,
then the base because I can not defer the check constraint (which
turns out not to be true but I didn't know that when I started down
this road).
Thank you all for helping,
Perry Smith ( pedz(at)easesoftware(dot)com )
Ease Software, Inc. ( http://www.easesoftware.com )
Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin M. Roy | 2007-07-22 21:18:52 | Re: posgres tunning |
Previous Message | Shreya Bhargava | 2007-07-22 18:55:59 | Re: Debugging postgresql source on gdb |