天天看點

pgsql編寫觸發器

建立觸發器函數

CREATE OR REPLACE FUNCTION update_sub_towncode_insert()
   RETURNS "trigger" AS
$BODY$
begin
if(length(NEW.towncode)>)
THEN
NEW.sub_towncode=subxzqhstr(NEW.towncode);
END IF;
RETURN NEW;
end
$BODY$
   LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION update_sub_towncode_insert() OWNER TO postgres;
           

建立觸發器

CREATE  TRIGGER update_sub_towncode_insert
   BEFORE INSERT
   ON poisexamine
   FOR EACH ROW
   EXECUTE PROCEDURE update_sub_towncode_insert();