Re: Rule/sequence weirdness - Mailing list pgsql-general

From Richard Huxton
Subject Re: Rule/sequence weirdness
Date
Msg-id 413588B2.6070708@archonet.com
Whole thread Raw
In response to Rule/sequence weirdness  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-general
Steve Crawford wrote:
>
> I want to monitor inserts to table "foo":
> guid: integer not null default nextval('public.guid'::text)
> end_time: integer
[snip]
> I expected the guid to match. Unfortunately there are no matching
> guids between the two tables. It appears that the sequence is being
> called twice so the guid in the log table is one greater than the
> guid in the main table.
>
> Did I miss something in my rule logic or is this a bug?

Rules are simply macros, so you are right and the sequence will be
accessed twice. You'll want to look at triggers.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: John Sidney-Woollett
Date:
Subject: Re: Suppress output from psql?
Next
From: Daniel Schuchardt
Date:
Subject: Re: Exporting/moving Postgress Instance