From: Phuong Ma <pma@commandprompt.com>
To: pgsql sql <pgsql-sql@postgresql.org>
To: Postgres-general <pgsql-general@postgresql.org>
Subject: trigger on DELETE
Date: Wed, 11 Jul 2001 15:56:55 -0700
Message-ID: <3B4CD9B7.B79DF11D@commandprompt.com> (raw)
Hello everyone,
I'm trying to define a trigger that copies the row to be deleted into
another table (which is the inventory_audit table) before it does the
delete from the original table (which is the inventory table).
CREATE FUNCTION inv_audit_mod () RETURNS OPAQUE AS '
BEGIN
NEW.user_aud := current_user;
NEW.mod_time := ''NOW'';
INSERT INTO inventory_audit
SELECT * FROM inventory WHERE id=NEW.id;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER inv_audit_mod BEFORE
DELETE ON inventory
FOR EACH ROW EXECUTE PROCEDURE inv_audit_mod();
Ok, the function works only with a trigger that is defined as ON INSERT
OR UPDATE. If I try to define a trigger for ON DELETE and then delete a
row from the table, there is nothing in the 'NEW' variable to return. I
get an error message. If I define the function to return NULL, 0, or
nothing, then it comes up with a type mis-match error. Is there anyone
who can help? Thanks.
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pma@commandprompt.com, pgsql-general@postgresql.org
Subject: Re: trigger on DELETE
In-Reply-To: <3B4CD9B7.B79DF11D@commandprompt.com>
* 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