Re: [SQL] Can I prevent my sequence to increment if an insert is rejected? - Mailing list pgsql-sql

From tjk@tksoft.com
Subject Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
Date
Msg-id 199907201901.MAA02467@uno.tksoft.com
Whole thread Raw
In response to Can I prevent my sequence to increment if an insert is rejected?  (Frederic De Leersnijder <frederic.de.leersnijder@pandora.be>)
List pgsql-sql
Frederic,

You could (a) do the work inside a transaction,
or (b) do the insert after you have retrieved
the key and verified it doesn't exist in the table.
I.e. get the nextval from the sequence first and then
do the insert.

P.S. If a record was inserted with a
used key, wouldn't you want to skip that
sequence value anyway?


Troy

Troy Korjuslommi                Tksoft OY, Inc.
tjk@tksoft.com                  Software Development
                                Open Source Solutions
                                Hosting Services




>
> Hi,
>
> when I try to insert a record and it curses with fields with a unique
> key on them my sequence I use for my primary key does increment. How can
> I prevent this from happening?
>
>
> Thanks
> Frederic
>
>

pgsql-sql by date:

Previous
From: Frederic De Leersnijder
Date:
Subject: Can I prevent my sequence to increment if an insert is rejected?
Next
From: "Gunnar Ingvi Thorisson"
Date:
Subject: Bad update performance?