pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ferdinand Smit <ferdinand@telegraafnet.nl>
To: Mr OCP <mr_ocp@yahoo.com>
To: pgsql-admin@postgresql.org
Subject: Re: Please help
Date: Tue, 20 Nov 2001 16:44:19 +0100
Message-ID: <200111201548.fAKFmPS03986@server9.telegraafnet.nl> (raw)
In-Reply-To: <20011116021806.20613.qmail@web20606.mail.yahoo.com>
References: <20011116021806.20613.qmail@web20606.mail.yahoo.com>

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



view thread (10+ messages)  latest in thread

Message-ID: <200111201548.fAKFmPS03986@server9.telegraafnet.nl>
Permalink:  ../200111201548.fAKFmPS03986@server9.telegraafnet.nl/
Also on:    postgresql.org/message-id/200111201548.fAKFmPS03986@server9.telegraafnet.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: ferdinand@telegraafnet.nl, mr_ocp@yahoo.com
  Subject: Re: Please help
  In-Reply-To: <200111201548.fAKFmPS03986@server9.telegraafnet.nl>
  References: <20011116021806.20613.qmail@web20606.mail.yahoo.com> <200111201548.fAKFmPS03986@server9.telegraafnet.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox