Re: possible bug using combination of 'serial' and rule

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: ralph(dot)heinkel(at)web(dot)de
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: possible bug using combination of 'serial' and rule
Date: 2004-11-01 15:12:49
Message-ID: 20041101151249.GB18231@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sun, Oct 31, 2004 at 03:37:26PM +0000, Ralph Heinkel wrote:
>
> I think this is a bug (I hope not a feature).

It's a feature.

> For each insert into table 'tmp' the serial counter is increased
> twice, once to create the entry in 'tmp', once for 'log'. The problem
> is that the rule does not see the correct 'storage_id'!!!

Rules are macros, so when you refer to NEW.storage_id in the rule
then the default expression "nextval('tmp_storage_id_seq')" is
evaluated again. If you don't want that to happen then use a
trigger.

This comes up often -- maybe somebody could add it to the FAQ.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Gaetano Mendola 2004-11-01 17:53:45 Re: Not a real bug, but an error
Previous Message Richard Huxton 2004-11-01 15:00:01 Re: possible bug using combination of 'serial' and rule