1 SET search_path TO public;
3 CREATE OR REPLACE FUNCTION table_log_pl_init(level int, orig_schema text, orig_name text, log_schema text, log_name text)
8 level_create text = E'''';
12 -- Quoted qualified names
13 orig_qq := quote_ident(orig_schema)||'.'||quote_ident(orig_name);
14 log_qq := quote_ident(log_schema)||'.'||quote_ident(log_name);
17 level_create := level_create
18 ||', trigger_id BIGSERIAL NOT NULL PRIMARY KEY';
20 level_create := level_create
21 ||', trigger_user VARCHAR(32) NOT NULL';
25 'table_log_pl_init: First arg has to be 3, 4 or 5.';
30 EXECUTE 'CREATE TABLE '||log_qq
32 ||', trigger_mode VARCHAR(10) NOT NULL'
33 ||', trigger_tuple VARCHAR(5) NOT NULL'
34 ||', trigger_changed TIMESTAMPTZ NOT NULL'
38 EXECUTE 'CREATE TRIGGER "table_log_trigger_pl" AFTER UPDATE OR INSERT OR DELETE ON '
39 ||orig_qq||' FOR EACH ROW EXECUTE PROCEDURE table_log_pl('
40 ||quote_literal(log_name)||','
42 ||quote_literal(log_schema)||')';
49 CREATE OR REPLACE FUNCTION table_log_pl_init(level int, orig_name text)
54 PERFORM table_log_pl_init(level, orig_name, current_schema());
61 CREATE OR REPLACE FUNCTION table_log_pl_init(level int, orig_name text, log_schema text)
65 PERFORM table_log_pl_init(level, current_schema(), orig_name, log_schema);
72 CREATE OR REPLACE FUNCTION table_log_pl_init(level int, orig_schema text, orig_name text, log_schema text)
76 PERFORM table_log_pl_init(level, orig_schema, orig_name, log_schema,
77 CASE WHEN orig_schema=log_schema
78 THEN orig_name||'_log' ELSE orig_name END);