CREATE FUNCTION change_trigger() RETURNS trigger AS $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO logging.t_history (tabname, schemaname, operation, new_val) VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, row_to_json(NEW)); RETURN NEW; ELSIF TG_OP = 'UPDATE' THEN INSERT INTO logging.t_history (tabname, schemaname, operation, new_val, old_val) VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, row_to_json(NEW), row_to_json(OLD)); RETURN NEW; ELSIF TG_OP = 'DELETE' THEN INSERT INTO logging.t_history (tabname, schemaname, operation, old_val) VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, row_to_json(OLD)); RETURN OLD; END IF; END; $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
On 05/15/2018 05:28 AM, Łukasz Jarych wrote: Hi Guys, I am using postgres 10.3 (or 4?). IT is possible to set up variable inside function? Like this?:https://www.postgresql.org/docs/10/static/plpgsql-declarations.html Best, Jacek -- Adrian Klaveradrian.klaver@aklaver.com
Hi Guys, I am using postgres 10.3 (or 4?). IT is possible to set up variable inside function?
Best, Jacek
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных