PostgreSQL继承:父表触发器是继承的吗?

时间:2013-02-09 11:58:02

标签: postgresql inheritance triggers timestamp postgresql-9.2

如果我在CANINES表上有一个更新前触发器,它将timestamp列设置为now(),而DOGS继承自CANINES,当更新DOGS行时,是否应该触发CANINES更新触发器?在我的测试中它没有,所以我怀疑答案是,但也许我没有做正确的事情:

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

1 个答案:

答案 0 :(得分:8)

长话短说 - 不,它不是遗传的。可以选择CREATE TABLE - LIKE ... INCLUDING ...,但它也不会传播触发器。