Re: Rule uses wrong value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Boes <jboes(at)nexcerpt(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rule uses wrong value
Date: 2004-10-12 15:48:55
Message-ID: 3744.1097596135@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Boes <jboes(at)nexcerpt(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2004-10-12 15:50:30 Re: Message-ID as unique key?
Previous Message Tom Lane 2004-10-12 15:37:45 Re: Confused with LABEL and LOOP