On 07/10/2018 02:30 AM, Łukasz Jarych wrote:
Maybe yes,
but for me when i am learning it is not...
The example function. It is a minimal example but it should serve as a
starting point.:
CREATE OR REPLACE FUNCTION public.add_trigger(tbl_name character varying)
RETURNS void
LANGUAGE plpgsql
AS $function$
BEGIN
EXECUTE 'CREATE TRIGGER ' || quote_ident(tbl_name||'_change') || '
AFTER UPDATE ON ' || quote_ident(tbl_name) || ' EXECUTE PROCEDURE
ts_update()';
END;
$function$
;
create table trg_test(id int, fld_1 varchar);
test=> \d trg_test
Table "public.trg_test"
Column | Type | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
id | integer | | |
fld_1 | character varying | |
select add_trigger('trg_test');
test=> \d trg_test
Table "public.trg_test"
Column | Type | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
id | integer | | |
fld_1 | character varying | | |
Triggers:
trg_test_change AFTER UPDATE ON trg_test FOR EACH STATEMENT EXECUTE
PROCEDURE ts_update()
Best,
Jacek
wt., 10 lip 2018 o 11:29 Guillaume Lelarge <guillaume@xxxxxxxxxxxx
--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx