Re: problem with sequence.....

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: problem with sequence.....
Date: 2006-08-16 14:17:35
Message-ID: 20060816141735.GB25228@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Aug 16, 2006 at 05:01:09PM +0530, Penchalaiah P. wrote:
> If again I pass correct values to that function that values can see in
> view data with increment value of sequence
>
>
> Any one can tell me how to stop that sequence value when ever I was
> passing wrong values to that function....

I'm not entirely sure I understood you, but if what you're asking is
for the sequence not to increment on transaction rollback, then you
can't have it. The sequence system guarantees that the numbers will
be in increasing order (subject to rollover), but it does not
guarantee that there will be no gaps. This is to avoid some
unpleasant concurrency side-effects from the no-gaps approach. If
you really need that, then you have two choices:

1. Roll your own, using some sort of interlock table. This will
not play nicely with a lot of concurrent writes, however (which is
the disadvantage the current implementation is designed to avoid).

2. In recent PostgreSQL releases, you could use a savepoint. So,
get the nextval() of your serial number. Set a savepoint. Try your
insert. If that fails, roll back and save the currval() as VOIDed.
(This isn't completely safe. You can make it completely safe by
doing it in two transactions, but that's best left as an exercise for
the reader.)

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
If they don't do anything, we don't need their acronym.
--Josh Hamilton, on the US FEMA

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rodrigo De León 2006-08-16 15:28:27 Re: Undo an update
Previous Message Penchalaiah P. 2006-08-16 11:31:09 problem with sequence.....