iterating over all NEW.* values in a trigger?
От | Louis-David Mitterrand |
---|---|
Тема | iterating over all NEW.* values in a trigger? |
Дата | |
Msg-id | 20010222164423.A1131@apartia.ch обсуждение исходный текст |
Список | pgsql-general |
Inside a plpgsql function trigger, is it possible to a loop over all fields of the NEW record (and inspect their value) without knowing in advance from which table NEW will come? I am trying the following: DROP FUNCTION arch_func(); CREATE FUNCTION arch_func() RETURNS opaque AS ' DECLARE rec ecord; BEGIN FOR rec IN SELECT a.attname,t.typname FROM pg_attribute a JOIN pg_class c ON (a.attrelid = c.oid AND c.relname = TG_RELNAME) JOIN pg_type t ON (t.oid = a.atttypid) LOOP RAISE NOTICE ''Hello %: %!'', rec.attname, rec.typname; -- -- here I would like to access NEW.rec.attname in order to be able -- to: -- 1) compare it to OLD.rec.attname, -- 2) check if there is a change, -- 3) save a changed value in another "archive" table -- END LOOP; RETURN NULL; END; ' LANGUAGE 'plpgsql'; DROP TRIGGER arch_after ON auction; CREATE TRIGGER arch_after AFTER UPDATE OR DELETE ON auction FOR each ROW EXECUTE PROCEDURE arch_func(); -- PHEDRE: Dans mes jaloux transports je le veux implorer. Que fais-je ? O� ma raison va-t-elle s'�garer ? (Ph�dre, J-B Racine, acte 4, sc�ne 6)
В списке pgsql-general по дате отправления: