Re: postgresql rule bug - Mailing list pgsql-bugs

From wieck@debis.com (Jan Wieck)
Subject Re: postgresql rule bug
Date
Msg-id m12fM0L-0003l8C@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to Re: postgresql rule bug  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Tom Lane wrote:

> Coranth Gryphon <gryphon@healer.com> writes:
> > Hi. From the contributors list, you seemed to be the most likely
> > people to send a postgresql bug report.
>
> There is a bugs list, which is the appropriate place.

    It's not a bug, it's a feature :-)

> > When using a RULE that triggers off an INSERT on a table whose
> > primary key is a SERIAL, every time the rule accesses the new
> > serial id in the body of the rule, the serial number increments.
>
> Wouldn't surprise me.  A rule is basically like a macro --- it's
> expanded with the original inputs substituted in each appropriate place.
> This is either a bug or a feature depending on what sort of example you
> are looking at ...
>
> In this particular case it does seem rather annoying, since there's
> no obvious way to get the behavior you're after.  I dunno if we
> can do anything about it in the near future though.

    Absolutely  right,  and I don't think we should/could fix it.
    Only a trigger will do it correctly in this case.

    The rule expands to a separate query, which is ran BEFORE the
    one  sent  to the backend. First of all, there's no guarantee
    that this additional query will produce the  same  number  of
    result rows (inserts) as the original one.

    Consider  the  case that someone does an INSERT ... SELECT to
    create new T_Comments.  Further take into  account  that  the
    rule  could  have  some  qualification  and  only some of the
    comments cause  additional  information  in  T_CommentHistory
    (where txtnote != '').

    Now  at  the time the INSERT for the history is executed, the
    system doesn't even know HOW MANY  rows  the  original  query
    will  produce.  How  should  it  preallocate  the serials and
    remember which ones to use when running the original query?

    Forget it and go for a trigger.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#========================================= wieck@debis.com (Jan Wieck) #

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Minimal patches for PostgreSQL 7.0b3 on NetBSD/alpha 1.4.1....
Next
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [SQL] Foreign keys breaks tables permissions