| От | John R Pierce |
|---|---|
| Тема | Re: How to auto-increment? |
| Дата | |
| Msg-id | 4B16F395.5000405@hogranch.com обсуждение исходный текст |
| Ответ на | How to auto-increment? (Andre Lopes <lopes80andre@gmail.com>) |
| Список | pgsql-general |
Andre Lopes wrote: > Hi, > > I have a table like this: > > id_product > id_increment > > and I need to increment values in id_increment like this > > prod_1 > 1 > > prod_1 > 2 > > prod_1 > 3 > > prod_2 > 1 > > Wich is the best way to do this? Using a trigger? Where can I find > examples of plpgsql doing this? offhand, I'd have another table that has (id_product primary key, next_increment integer), and use it to populate your id_increment fields, bumping the next_increment each time you fetch it. I assume its OK if there are missing increment values, like if you delete a product/increment from your table, or if in the middle of inserting a new one, there's a transaction rollback for some reason?
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера