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?



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to