Re: How to auto-increment?

Поиск
Список
Период
Сортировка
От 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 по дате отправления:

Предыдущее
От: Greg Williamson
Дата:
Сообщение: Re: How to auto-increment?
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: How to get RTREE performance from GIST index?