7

如果我在 CANINES 表上有一个更新前触发器,它将时间戳列设置为 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
4

1 回答 1

10

长话短说 - 不,它不是继承的。有CREATE TABLE-选项LIKE ... INCLUDING ...,但它也不会传播触发器。

于 2013-02-09T12:33:34.030 回答