Re: [SQL] Can I prevent my sequence to increment if an insert is rejected?
В списке pgsql-sql по дате отправления:
| От | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера