Re: RULE vs. SEQUENCE - Mailing list pgsql-hackers

From Jan Wieck
Subject Re: RULE vs. SEQUENCE
Date
Msg-id 200009041202.HAA02041@jupiter.jw.home
Whole thread Raw
In response to RULE vs. SEQUENCE  (Karel Zak <zakkr@zf.jcu.cz>)
Responses Re: RULE vs. SEQUENCE
List pgsql-hackers
Karel Zak wrote:
>
>
>  Hi,
>
>  I have a question... why RULE call nexval() and data in RULE statement are
> differend than data in original stmt.
   It's  a known "feature", and I don't know any way of changing   it.
   The problem is, that NEW.attname in a rule  means,  "whatever   is  in  the targetlist of the INSERT when applying
therule".   In your example, it'll be  a  call  to  nextval().  The  rule   system  doesn't  know  that  this
targetlistexpression has a   side-effect (incrementing the sequence).
 
   Thus, the rule creates a second query  which  does  it's  own   calls to nextval() when executed.

>  It's interesting feature (6.5, 7.0, 7.1...). How is a possible in RULE
> obtain same data as in 'aa' table for a default data from the sequence.
   The query rewrite rule system behaves like this since 4.2 (or   even earlier). Since 6.4 it does the right things
on UPDATE   and  DELETE  too.  Don't know when we introduced sequences or   better "functions that have such nasty
side-effects".


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #




pgsql-hackers by date:

Previous
From: Karel Zak
Date:
Subject: RULE vs. SEQUENCE
Next
From: Karel Zak
Date:
Subject: Re: RULE vs. SEQUENCE