Re: Rule uses wrong value - Mailing list pgsql-general

From Tom Lane
Subject Re: Rule uses wrong value
Date
Msg-id 3744.1097596135@sss.pgh.pa.us
Whole thread Raw
In response to Re: Rule uses wrong value  (Jeff Boes <jboes@nexcerpt.com>)
Responses Re: Rule uses wrong value  (Jeff Boes <jboes@nexcerpt.com>)
List pgsql-general
Jeff Boes <jboes@nexcerpt.com> writes:
> Tom Lane wrote:
>> No kidding.  A rule is a macro and therefore has the usual risks of
>> multiple evaluations of arguments.

> But shouldn't "new.job_id" use the value that was already recorded in
> the original row?

There is no "value that was already recorded in the original row";
if you want to think in those terms you should use a trigger.  It's
fundamentally wrong to think of a rule in that way.

In the rule, "new.job_id" is effectively a macro parameter that gets
replaced by the INSERT's corresponding expression, ie, nextval(...).

            regards, tom lane

pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: Message-ID as unique key?
Next
From: Tom Lane
Date:
Subject: Re: Change query priority