Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?

From: "tjk(at)tksoft(dot)com" <tk(at)uno(dot)tksoft(dot)com>
To: frederic(dot)de(dot)leersnijder(at)pandora(dot)be (Frederic De Leersnijder)
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
Date: 1999-07-20 19:01:34
Message-ID: 199907201901.MAA02467@uno.tksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)tksoft(dot)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
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gunnar Ingvi Thorisson 1999-07-20 23:06:15 Bad update performance?
Previous Message Frederic De Leersnijder 1999-07-20 16:54:11 Can I prevent my sequence to increment if an insert is rejected?