如果在CANINES表上有一个before update触发器,它将timestamp列设置为now(),并且DOGS继承自CANINES,那么当DOGS行被更新时,CANINES update触发器是否应该触发?在我的测试中没有,所以我怀疑答案是否定的,但也许我做得不对:
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
最佳答案
长话短说-不,不是遗传的。可以选择CREATE TABLE
-LIKE ... INCLUDING ...
,但它也不传播触发器。
关于postgresql - PostgreSQL继承:父表触发器是否被继承?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14787887/