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

Поиск
Список
Период
Сортировка
От tjk@tksoft.com
Тема Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
Дата
Msg-id 199907201901.MAA02467@uno.tksoft.com
обсуждение исходный текст
Ответ на Can I prevent my sequence to increment if an insert is rejected?  (Frederic De Leersnijder <frederic.de.leersnijder@pandora.be>)
Список 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 по дате отправления:

Предыдущее
От: Frederic De Leersnijder
Дата:
Сообщение: Can I prevent my sequence to increment if an insert is rejected?
Следующее
От: "Gunnar Ingvi Thorisson"
Дата:
Сообщение: Bad update performance?