triggers vs. 'NEW in non-rule query' -- SOLVED?

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: triggers vs. 'NEW in non-rule query' -- SOLVED?
Date: 2001-03-04 16:49:45
Message-ID: 20010304104945.B3610@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Sat, Mar 03, 2001 at 11:50:03PM -0500, Ron Peterson wrote:
>
> Could you provide an example of what *doesn't* work?
>

i THINK i've got it! MWAAH HA HA...

i follow the example from the postgresql-doc/html/user/c4*40.html
document and define a function to be called via TRIGGER...

CREATE FUNCTION easy() RETURNS OPAQUE AS '
DECLARE
x CHAR(1) := NEW.somefield FROM 1 FOR 1;
BEGIN
-- whatever, yada yada, bada bing bada boom
RETURN NEW;
END;
' language 'plpgsql';

and this results in "ERROR: use of NEW in non-rule procedure"
when actually called via TRIGGER. i change it instead to

CREATE FUNCTION easy() RETURNS OPAQUE AS '
DECLARE
x CHAR(1); -- no := assignment here
BEGIN
x := NEW.somefield FROM 1 FOR 1;
-- whatever, yada yada, bada bing bada boom
RETURN NEW;
END;
' language 'plpgsql';

and suddenly all is right with the world. so i can't refer to the
NEW (or probably OLD) pseudotables WITHIN THE DECLARE section.
apparently.

Q: is this a bug? is this a feature?

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
-- Isaac Asimov, 'The Genetic Code'

will(at)serensoft(dot)com
http://groups.yahoo.com/group/newbieDoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Boulat Khakimov 2001-03-04 17:00:31 How to Describe a field in the table???
Previous Message Tom Lane 2001-03-04 16:39:14 Re: postgres locks...