Author: Not specified Language: text
Description: Not specified Timestamp: 2013-05-20 11:19:56 +0000
View raw paste Reply
  1.  
  2. CREATE OR REPLACE FUNCTION _audit() RETURNS TRIGGER AS $$
  3. BEGIN
  4.         IF (TG_OP = 'DELETE') THEN
  5.                 INSERT INTO audit.TG_TABLE_NAME SELECT 'DELETE'::operation_t, now(), CURRENT_ROLE, OLD.*;
  6.                 RETURN OLD;
  7.         ELSIF (TG_OP = 'UPDATE') THEN
  8.                 INSERT INTO audit.TG_TABLE_NAME SELECT 'UPDATE'::operation_t, now(), CURRENT_ROLE, NEW.*;
  9.                 RETURN NEW;
  10.         ELSIF (TG_OP = 'INSERT') THEN
  11.                 INSERT INTO audit.TG_TABLE_NAME SELECT 'INSERT'::operation_t, now(), CURRENT_ROLE, NEW.*;
  12.                 RETURN NEW;
  13.         END IF;
  14.         RETURN NULL;
  15. END;
  16. $$ LANGUAGE plpgsql;
  17.  
View raw paste Reply