| От | Matthew T. O'Connor |
|---|---|
| Тема | Re: Abort state on duplicated PKey in transactions |
| Дата | |
| Msg-id | 002201c13882$63f83780$0b01010a@zeut обсуждение исходный текст |
| Ответ на | Abort state on duplicated PKey in transactions (Haroldo Stenger <hstenger@adinet.com.uy>) |
| Список | pgsql-hackers |
> A solution, could be to query for the existance of the PK, just before the > insertion. But there is a little span between the test and the > insertion, where another insertion from another transaction could void > the existance test. Any clever ideas on how to solve this? Using > triggers maybe? Other solutions? > All you need to do is use a sequence. If you set the sequence to be the primary key with a default value of nextval(seq_name) then you will never have a collision. Alternatly if you need to know that number before you start inserting you can select next_val(seq_name) before you inser and use that. By the way the datatype serial automates exactly what I described.
В списке pgsql-hackers по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера