Re: postgresql rule bug

From: wieck(at)debis(dot)com (Jan Wieck)
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Coranth Gryphon <gryphon(at)healer(dot)com>, scrappy(at)hub(dot)org, Jan Wieck <wieck(at)debis(dot)com>, bugs(at)postgresql(dot)org
Subject: Re: postgresql rule bug
Date: 2000-04-12 12:12:21
Message-ID: m12fM0L-0003l8C@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tom Lane wrote:

> Coranth Gryphon <gryphon(at)healer(dot)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(at)debis(dot)com (Jan Wieck) #

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jan Wieck 2000-04-12 12:25:49 Re: [SQL] Foreign keys breaks tables permissions
Previous Message Peter Eisentraut 2000-04-12 10:24:41 Re: Minimal patches for PostgreSQL 7.0b3 on NetBSD/alpha 1.4.1....