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

Поиск
Список
Период
Сортировка
От Josh Kupershmidt
Тема Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Дата
Msg-id BANLkTin=Z+JZLwXKOnNmxcDKt2aXr8p4vg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers