Re: trigger: NEW/OLD-error or nothing happens - Mailing list pgsql-general

From Joe Conway
Subject Re: trigger: NEW/OLD-error or nothing happens
Date
Msg-id 003001c1072f$0dbd6d60$0205a8c0@jecw2k1
Whole thread Raw
In response to trigger: NEW/OLD-error or nothing happens  (Knut Suebert <knut.suebert@web.de>)
Responses Re: trigger: NEW/OLD-error or nothing happens
List pgsql-general
> create function nac_viceversa() returns opaque as'
> begin
> NEW.minport := nacmin(OLD.sport,OLD.dport);
> NEW.maxport := nacmax(OLD.sport,OLD.dport);
> return NEW;
> end;
> 'language 'plpgsql';
>
> create trigger nac_update after insert or update on traf
> for each row execute procedure nac_viceversa();
>
> but than
>
> ERROR:  record old is unassigned yet
>
> if i take NEW. instead of OLD.: no errors -- but minport and maxport
> are empty after insert. (could it be that OLD makes no sense on
> insert? I'd lie if I'd say that I understood the conecpt, but
> databases are hard stuff for me even in my native language)

OLD does not make sense on an insert because there is no "OLD" data for a
brand new row. Similarly, there is no "NEW" data during a delete. See
http://www.postgresql.org/idocs/index.php?plpgsql-trigger.html

NEW
Data type RECORD; variable holding the new database row on INSERT/UPDATE
operations on ROW level triggers.

OLD
Data type RECORD; variable holding the old database row on UPDATE/DELETE
operations on ROW level triggers.

Hope this helps,

Joe



pgsql-general by date:

Previous
From: Knut Suebert
Date:
Subject: trigger: NEW/OLD-error or nothing happens
Next
From: "Peter C. A. Bär"
Date:
Subject: Re: A quick SUSE question...