PostgreSQL Inheritance: Parent Table Triggers Inherited?

If I have a trigger before updating in the CANINES table that sets the timestamp now () column, and DOGS inherits from CANINES, when the DOGS row is updated, does the CANINES update trigger fire? This is not the case in my tests, so I suspect the answer is “No,” but maybe I didn’t do everything right:

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
+5
source share
1 answer

In short - no, this is not inherited. There is a CREATE TABLE- option LIKE ... INCLUDING ..., but it also does not apply to triggers.

+7
source

All Articles