If I have a before-update trigger on CANINES table that sets a timestamp column to now(), and DOGS inherits from CANINES, when a DOGS row is updated, is the CANINES update-trigger supposed to fire? In my tests it does not, so I suspect the answer is No, but maybe I’ve not done things correctly:
create table canines
(
lastupdate timestamp with time zone default now()
);
CREATE OR REPLACE FUNCTION stamp_lastupdate_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.lastupdate = now();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER TRG_CANINES_BU BEFORE UPDATE
on CANINES FOR EACH ROW EXECUTE PROCEDURE
stamp_lastupdate_column();
create table dogs
(id int primary key,
breed varchar(25)
) inherits (CANINES);
insert into dogs(id, breed) values(1, 'sheltie');
select * from dogs;
--"2013-02-09 06:49:31.669-05" , 1 , sheltie
update dogs set breed = 'Sheltie/Shetland Sheepdog' where id = 1;
select * from dogs;
--"2013-02-09 06:49:31.669-05" , 1 , Sheltie/Shetland Sheepdog
Long story short – no, it’s not inherited. There is option to
CREATE TABLE–LIKE ... INCLUDING ..., but it also doesn’t propagate triggers.