Обсуждение: Inheritance and such
Hi everyone, I ran into a brick wall when I realized that inheritance in postgres isnt really there... Here's a description of the relevant part of my schema. CREATE TABLE base ( id serial not null primary key, <some base columns> ); CREATE TABLE specialized ( <some specialized columns> ) INHERITS base; CREATE TABLE specialized2 ( <some specialized columns> ) INHERITS base; CREATE TABLE events ( id serial not null primary key, baseid int references base(id) <some other columns> ); This does not work if I load a bunch of records into specialized and then try to refer to the id's through the event's table because Postgres doesn't do N-table indexes where N is greater than 1 :-P This whole part of my schema, if it worked, would be so incredibly useful, as I would be able to add as many specialized tables as needed, and still use the same sql to create events for them, and access their base table's data, etc. So I have 3 questions: Is any work being done currently to fix our implementation of inheritance? How much work would it take to do this? and lastly, how can I implement my schema to do something similar, emulated, or otherwise that will work with postgres as it is now? Thanks, John Hughes Wetleads.com
On Fri, Apr 01, 2005 at 09:51:25AM -0600, John Hughes <johnh@wetleads.com> wrote a message of 49 lines which said: > I ran into a brick wall when I realized that inheritance in postgres > isnt really there... I have a problem which MAY be in the same category. CREATE TABLE base ( id serial not null primary key, <some base columns> ); CREATE TABLE specialized ( <some specialized columns> ) INHERITS base; Now, I try to set up a trigger AFTER UPDATE ON base but, when I update "specialized", the trigger is not called. Same thing with CREATE or DELETE. I have to define the trigger to be AFTER UPDATE ON specialized. Is it normal? PostgreSQL 7.4
Stephane Bortzmeyer schrieb: > >I have a problem which MAY be in the same category. > >CREATE TABLE base ( > id serial not null primary key, > <some base columns> >); > >CREATE TABLE specialized ( ><some specialized columns> >) INHERITS base; > >Now, I try to set up a trigger AFTER UPDATE ON base but, when I update >"specialized", the trigger is not called. Same thing with CREATE or >DELETE. I have to define the trigger to be AFTER UPDATE ON >specialized. Is it normal? > > > Yes, thats known. You have to define a trigger on each child table. You can point that trigger on the same function. Daniel.