Re: incrementing updates and locks

From: Craig James <craig_james(at)emolecules(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: incrementing updates and locks
Date: 2010-09-17 00:04:16
Message-ID: 4C92B080.3080800@emolecules.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 9/16/10 4:17 PM, Aras Angelo wrote:
> Daniel, Craig
>
> The gaps are not really expected. It is set once only.
> Its about printing packing slips for ecommerce orders. We have the ORDER ID sequence, but so many different stations are accessing these orders, if my station print the next 100 orders from the que, id like to give them values starting from MAX(print_number_sequence so far) AND +1, +2, +3, .... +100.
>
> I hope this clears it better. I think a sequence can work. My concern was performance, as in the actual programming LOOP, querying the max field, assigning the row number, reissuing the max field. A sequence i guess, would perform better than a regular table index?

Sequences are very fast. Just do something like this:

update mytable set order_id = nextval('order_id_seq') where ...

Using this technique, you will only get gaps in the sequence if something goes wrong and the transaction is rolled back. But given what you have told us about your application, it is probably not very important if a few ORDER ID numbers are missing.

Craig

> On Thu, Sep 16, 2010 at 4:06 PM, Craig James <craig_james(at)emolecules(dot)com <mailto:craig_james(at)emolecules(dot)com>> wrote:
>
> On 9/16/10 3:54 PM, Aras Angelo wrote:
>
> Hello All
>
> I have a column in my table which is incrementally updated.
>
>
> Try to give us more details...
>
> Does the column need have contiguous values or are "gaps" ok? That is, does it have to be 1,2,3,4,...,N-1,N or is it ok to have something like 1,3,4,7,...,M (where M>N) for N rows?
>
> Is the value updated every time the row is changed, or is it set once only?
>
> If gaps are OK, then a sequence is a simple answer.
>
> Craig
>
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org <mailto:pgsql-admin(at)postgresql(dot)org>)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message donghe 2010-09-17 01:20:46 issue pgsql_tmp keeps increasing
Previous Message Aras Angelo 2010-09-16 23:21:57 Re: incrementing updates and locks