Skip site navigation (1) Skip section navigation (2)

Re: Please help

From: Ferdinand Smit <ferdinand(at)telegraafnet(dot)nl>
To: Mr OCP <mr_ocp(at)yahoo(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Please help
Date: 2001-11-20 15:44:19
Message-ID: 200111201548.fAKFmPS03986@server9.telegraafnet.nl (view raw or flat)
Thread:
Lists: pgsql-admin
Hi Mike,

> Can anyone help me write a trigger on a table, I have
> created an audit table for a table and what I want
> trigger to do is to whenever a record is deleted from
> the table it should first be inserted into the audit
> table, just to keep track of whatever records are
> deleted.

Is this something ?? This archives my adres changes.

  /* Archive function */
  DROP FUNCTION fn_archive();
  CREATE FUNCTION fn_archive() RETURNS OPAQUE AS '
    BEGIN
      /* TG_OP is the function (UPDATE, DELETE, SELECT) */
      INSERT INTO adres_archive
          VALUES (OLD.name,OLD.adres,OLD.tel,current_user,now(),tg_opt);
        NEW.modtime := ''now'';
      END IF;

      RETURN NEW;
    END;
  ' LANGUAGE 'plpgsql';

  /* Archive trigger */
  DROP TRIGGER tr_archive ON adres;
  CREATE TRIGGER tr_adres_archive BEFORE UPDATE OR DELETE
  ON adres FOR EACH ROW
  EXECUTE PROCEDURE fn_archive ();

Ferdinand Smit

In response to

pgsql-admin by date

Next:From: Brian McCaneDate: 2001-11-20 16:19:01
Subject: Time Zones and Brain Damage :)
Previous:From: Bruce MomjianDate: 2001-11-20 15:33:08
Subject: Re: Genetic algorithms

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group