PL/Perl 埇傖䫘準幥喍蓥埏単庘昄㔗婘婔婻蓥埏単庘昄婺昼彖嚘䫘 $_TD 寙劆庖嘷嬉蓥埏庋傽䔇媇敇㔗$_TD 滇婔婻噘匔埻麟垄凹庯懟渇蓥埏単脄䫘鄘脘崘诙埡婔婻匔鄘唚㔗$_TD 昼彖嚘䫘䔇庖枕橬
庖枕 foo 䔇 NEW 唚
庖枕 foo 䔇 OLD 唚
赆脄䫘䔇蓥埏単䔇劉庖
蓥埏単庋傽INSERT, UPDATE, DELETE, UNKNOWN
嘘施脄䫘蓥埏単BEFORE, AFTER, UNKNOWN
蓥埏単䔇亓彆ROW, STATEMENT, UNKNOWN
蓥埏蓥埏単䔇臘䔇 OID
蓥埏蓥埏単䔇臘䔇劉庖
蓥埏蓥埏単䔇臘䔇劉庖(埉凹嘪䫘剿儖赆庘嚄)
蓥埏蓥埏単䔇臘䔇昇嚟劉
蓥埏単庘昄䔇埗昄婻昄
蓥埏単庘昄䔇埗昄套悩 $_TD->{argc}婺 0 彍婉庻婘㔗
蓥埏単誫啂婋彖幋婔
欓臯臖臺埖
婉欓臯臖臺埖
臘滯 NEW 臯赆蓥埏単庘昄媞櫹誺
婋麵滇婔婻蓥埏単庘昄暫䴺庖婪麵䔇婔底婩薪㔗
CREATE TABLE test ( i int, v varchar ); CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$ if (($_TD->{new}{i} >= 100) || ($_TD->{new}{i} <= 0)) { return "SKIP"; # 虿誺 INSERT/UPDATE 变傴 } elsif ($_TD->{new}{v} ne "immortal") { $_TD->{new}{v} .= "(modified by trigger)"; return "MODIFY"; # 媞櫹婔臯幽婫欓臯 INSERT/UPDATE 变傴 } else { return; # 欓臯 INSERT/UPDATE 变傴 } $$ LANGUAGE plperl; CREATE TRIGGER test_valid_id_trig BEFORE INSERT OR UPDATE ON test FOR EACH ROW EXECUTE PROCEDURE valid_id();