UPDATE事件触发器函数
最近更新时间: 2024-10-17 17:10:00
不准许更新t_trigger.nc字段值为 TDSQL PG。
postgres=# CREATE OR REPLACE FUNCTION t_trigger_update_trigger_func() RETURNS trigger AS
postgres-# $$
postgres$# BEGIN
postgres$# --不准许t_trigger.nc值为 TBase
postgres$# IF NEW.nc = 'TDSQL PG' THEN
postgres$# NEW.nc = OLD.nc ;
postgres$# END IF;
postgres$# RETURN NEW;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# CREATE TRIGGER t_trigger_update_trigger BEFORE UPDATE ON t_trigger FOR EACH ROW EXECUTE PROCEDURE t_trigger_update_trigger_func();
CREATE TRIGGER
postgres=# UPDATE t_trigger SET nc='TDSQL PG' WHERE id=1;
UPDATE 1
postgres=# SELECT * FROM t_trigger ;
id | nc
----+-------------------------
1 | TDSQLPG_0.426093454472721
(1 row)
postgres=#