Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers - Mailing list pgsql-docs

From Josh Kupershmidt
Subject Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Date
Msg-id BANLkTin=Z+JZLwXKOnNmxcDKt2aXr8p4vg@mail.gmail.com
Whole thread Raw
In response to Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
List pgsql-docs
On Thu, May 5, 2011 at 10:36 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> That is, in fact, exactly the behavior you get if you declare a RECORD
> variable and set it to NULL.  If these variables were indeed not
> declared, you'd get a complaint about "new" not being a known variable.

Hrm, guess I learned something. I tested with a trigger function which used:
...
     IF NEW IS NULL THEN
       RAISE NOTICE 'new is null.';
...

which was giving me 'ERROR:  record "new" is not assigned yet' when
used as an on-delete trigger. I am a little surprised that you can't
use IS NULL to test out a record-type variable which you've just
declared to be NULL, e.g. this function blows up:

CREATE OR REPLACE FUNCTION test_trg() RETURNS TRIGGER AS $$
  DECLARE SOMEVAR record;
  BEGIN
     SOMEVAR := NULL;
     IF SOMEVAR IS NULL THEN
       RAISE NOTICE 'somevar is null.';
     END IF;
  RETURN NEW;
  END;
$$ LANGUAGE plpgsql;

with the same error message.

Josh

pgsql-docs by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers