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



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to