From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Foster, Stephen <stephenlfoster@comcast.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Trigger/Sequence headache
Date: Sun, 12 Feb 2006 15:10:33 -0800 (PST)
Message-ID: <20060212150559.S97294@megazone.bigpanda.com> (raw)
In-Reply-To: <000801c63023$8e0af830$2101a8c0@cfgod>
References: <000801c63023$8e0af830$2101a8c0@cfgod>
On Sun, 12 Feb 2006, Foster, Stephen wrote:
> This is going to be one of those stupid problems of mine. I have an
> insert trigger setup to verify that duplicate or repeating information
> isn't storage in the table. If trigger function finds the information
> as a duplicate it returns a NULL and the information isn't added; that
> works. The problem I'm having is that it is incrementing the sequence
> counter even when the data isn't added. Is this something that I have
> to live with or should I be returning something other than a NULL?
The sequence is going to increment upon getting the value.
However, I think, if instead of using a default, you got the next value in
the trigger after you determined that it wasn't a duplicate and set the
field, it wouldn't increment for this case. This changes some other
behaviors a little (for example DEFAULT in updates as well), so you'd need
to see whether it'd be acceptable.
Of course, errors, rollbacks and deletes will still leave holes.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone.bigpanda.com, stephenlfoster@comcast.net
Subject: Re: Trigger/Sequence headache
In-Reply-To: <20060212150559.S97294@megazone.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox