CREATE TABLE ${table}_log (
	${idField} VARCHAR(2048),
	operation VARCHAR(10),
	date TIMESTAMP DEFAULT current_timestamp,
	id SERIAL,
	status VARCHAR(10) DEFAULT ''
);
INSERT INTO ${table}_log SELECT ${idField}, 'insert', current_timestamp from ${table};

create or replace function notify_insert_${table}() returns trigger as $$
  begin
    insert into ${table}_log values (NEW.${idField}, 'insert');
    return NEW;
  end;
$$
language plpgsql volatile;

create or replace function notify_update_${table}() returns trigger as $$
  begin
    insert into ${table}_log values (NEW.${idField}, 'update');
    return NEW;
  end;
$$
language plpgsql volatile;

create or replace function notify_delete_${table}() returns trigger as $$
  begin
    insert into ${table}_log values (OLD.${idField}, 'delete');
    return NEW;
  end;
$$
language plpgsql volatile;


create trigger notify_insert_${table} 
	after insert on ${table} 
	for each row execute procedure notify_insert_${table}();

create trigger notify_update_${table} 
	after update on ${table}
	for each row execute procedure notify_update_${table}();

create trigger notify_delete_${table} 
	after delete on ${table} 
	for each row execute procedure notify_delete_${table}();
