Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 07F331337990 for ; Thu, 16 Sep 2010 20:09:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 39909-03 for ; Thu, 16 Sep 2010 23:09:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.djs-consulting.com (djs-consulting.com [173.203.86.83]) by mail.postgresql.org (Postfix) with ESMTP id AC4621337D58 for ; Thu, 16 Sep 2010 20:09:06 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.djs-consulting.com (Postfix) with ESMTP id 8407F34A73 for ; Thu, 16 Sep 2010 23:09:25 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at djs-consulting.com Received: from mail.djs-consulting.com ([127.0.0.1]) by localhost (djs-consulting.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G9CRim87YNE0 for ; Thu, 16 Sep 2010 23:09:23 +0000 (UTC) Received: from [192.168.0.101] (c-68-35-134-229.hsd1.nm.comcast.net [68.35.134.229]) (Authenticated sender: daniel@summershome.org) by mail.djs-consulting.com (Postfix) with ESMTPSA id 270B434A66 for ; Thu, 16 Sep 2010 23:09:23 +0000 (UTC) Message-ID: <4C92A38C.3020209@djs-consulting.com> Date: Thu, 16 Sep 2010 23:09:00 +0000 From: "Daniel J. Summers" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100826 Thunderbird/3.0.7 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: incrementing updates and locks References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/91 X-Sequence-Number: 35635 On 09/16/2010 10:54 PM, Aras Angelo wrote: > Hello All > > I have a column in my table which is incrementally updated. I cant set > this field to be a SERIAL because the value is not assigned at the > time of the INSERT, it is assigned later by the system by an UPDATE. > Whats the best way to achieve this by means of performance? It sounds like what you need is a sequence. http://www.postgresql.org/docs/8.3/static/sql-createsequence.html There is one gotcha - if you obtain a value from the sequence, and the transaction is rolled back, the value is *not* reissued; so, you could get gaps. If that's unacceptable, you might try indexing that field; I don't know if max uses them, but it'd be worth a try. -- _____________________________________________________ Daniel J. Summers Owner, DJS Consulting Albuquerque, NM, USA ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ E-mail ~ daniel@djs-consulting.com Website ~ http://djs-consulting.com Tech Blog ~ http://techblog.djs-consulting.com Personal Blog ~ http://daniel.summershome.org _____________________________________________________ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e h---- r+++ z++++