Re: Bug in plpgsql, when using NEW with composite field value.

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Oleg Serov" <serovov(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug in plpgsql, when using NEW with composite field value.
Date: 2008-12-10 10:45:19
Message-ID: 162867790812100245w5bf43a9cm411d7b6b58a55d0a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello

you have to use parenthesis, because parser don't distinguish between
variants schema.table.column and variable.field.attrib

example:

postgres=# create or replace function trgbody() returns trigger as $$
begin
raise notice '%', (new.a).a;
return new;
end $$ language plpgsql;
CREATE FUNCTION
postgres=# create type xx as (a integer, b integer);
CREATE TYPE
postgres=# create table g(a xx);
CREATE TABLE
postgres=# create trigger ggg before insert on g for each row execute
procedure trgbody();
CREATE TRIGGER
postgres=# insert into g values('(10,20)');
NOTICE: 10
INSERT 0 1

regards
Pavel Stehule

2008/12/10 Oleg Serov <serovov(at)gmail(dot)com>:
> SQL:
>
> 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
> QUERY: SELECT COALESCE(NEW.somecompositefield.field, TRUE)
> CONTEXT: SQL statement in PL/PgSQL function "bug_with_triggers" near line 2
>
>
> ********** ERROR **********
>
> ERROR: NEW used in query that is not in a rule
> SQL state: 42601
> Контекст:SQL statement in PL/PgSQL function "bug_with_triggers" near line 2
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2008-12-10 10:46:50 Re: plpgsql bug OR future request: Assign fileds in composite subfiled. eg. table.compositefield.subfield := TRUE;
Previous Message Oleg Serov 2008-12-10 10:19:15 plpgsql bug OR future request: Assign fileds in composite subfiled. eg. table.compositefield.subfield := TRUE;