Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgres audit table

create function tg_audit_dist_shard() returns trigger
    language plpgsql
as
$$
DECLARE
    audit_entry int := nextval('audit_entry_seq'::regclass);
BEGIN
    IF (TG_OP = 'INSERT') THEN
        INSERT INTO dist_shard_audit
        VALUES (now(), audit_entry, TG_OP::audit_action, TG_RELID::regclass, NEW.*);
        RETURN NEW;
    ELSIF (TG_OP = 'UPDATE') THEN
        INSERT INTO dist_shard_audit
        VALUES (now(), audit_entry, 'UPDATE_OLD'::audit_action, TG_RELID::regclass, OLD.*),
               (now(), audit_entry, 'UPDATE_NEW'::audit_action, TG_RELID::regclass, NEW.*);
    ELSIF (TG_OP = 'DELETE') THEN
        INSERT INTO dist_shard_audit
        VALUES (now(), audit_entry, TG_OP::audit_action, TG_RELID::regclass, OLD.*);
        RETURN OLD;
    END IF;
    RETURN NULL;
END;
$$;
Comment

PREVIOUS NEXT
Code Example
Sql :: SQL Primary Key Error 
Sql :: How to take sum of column with same id in "JPQL?" 
Sql :: t-sql email validation 
Sql :: min:sec datediff mssql 
Sql :: dump sql databse import export 
Sql :: how to make full text search dynamic in mysql 
Sql :: oracle select tree structure 
Sql :: undefined get_magic_quotes_gpc() in sqlite 
Sql :: how to take recent row without limit in mysql 
Sql :: download sql file of countries names 
Sql :: groupby sort sql hive 
Sql :: SOQL Parent to child 
Sql :: %ORACLE_HOME%database 
Sql :: mysql dump everythign 
Sql :: Duplix print in Smartforms 
Sql :: visual c++ 2019 redistributable package mysql workbench 
Sql :: sql or operator 
Sql :: sqlite date to char 
Sql :: sql saut de ligne 
Sql :: Xampp resolve mysql issue 
Sql :: sql update from another table join 
Sql :: including parameters in OPENQUERY 
Sql :: mysqli count down 
Sql :: VERIFY INDEXES WITH PARTITIONS IN SQL ORACLE 
Sql :: Select Some From A Table In MySQL Database 
Sql :: online convert linq to sql query 
Sql :: sqlite 
Sql :: how to filter in sql 
Sql :: sql select all from one table and one column from another 
Sql :: like and not like together in sql 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =