Re: Bug in plpgsql, when using NEW with composite field value. - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Bug in plpgsql, when using NEW with composite field value.
Date
Msg-id 2859.1228927452@sss.pgh.pa.us
Whole thread Raw
In response to Bug in plpgsql, when using NEW with composite field value.  ("Oleg Serov" <serovov@gmail.com>)
List pgsql-bugs
"Oleg Serov" <serovov@gmail.com> writes:
> CREATE OR REPLACE FUNCTION "bug_with_triggers" () RETURNS trigger AS
> $body$
> BEGIN
>     PERFORM COALESCE(NEW.some_composite_field.field, TRUE);
> END;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

> Error:
> ERROR:  NEW used in query that is not in a rule

I agree that this error message is pretty unhelpful, but the code is
wrong anyway.  The correct way to do this is
    PERFORM COALESCE((NEW.some_composite_field).field, TRUE);

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Yuri Steindorfer"
Date:
Subject: Connection refused
Next
From: Tom Lane
Date:
Subject: Re: BUG #4565: nextval not updated during wal replication, leading to pk violations