Please help - Mailing list pgsql-admin

From Tariq Muhammad
Subject Please help
Date
Msg-id Pine.LNX.4.21.0204101147230.21405-100000@genesis.int.libertyrms.com
Whole thread Raw
In response to Re: Timestamps and performances problems  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-admin
Hi Folks

I am trying to write a function that should archive old values to an
archiving table before update on the orignal table but it inserts both old
and new values to the archiving table here is the code:

  CREATE FUNCTION fn_archive_01() RETURNS OPAQUE AS '
    BEGIN
      /* TG_OP is the function (UPDATE, DELETE, SELECT) */
      INSERT INTO customer_archive
          VALUES
(OLD.id, OLD.name,current_user,now(),TG_OP);

     IF TG_OP = ''UPDATE''
      THEN
        RETURN NEW;
      END IF;

      RETURN OLD;
    END;
  ' LANGUAGE 'plpgsql';



CREATE TRIGGER tr_customer_archive_del BEFORE DELETE
   ON customer FOR EACH ROW
   EXECUTE PROCEDURE fn_archive_01();

Thanks for your help
Tariq



pgsql-admin by date:

Previous
From: Jean-Christophe ARNU (JX)
Date:
Subject: Timestamps and performances problems
Next
From: "Dave Menendez"
Date:
Subject: Query planner quirk?