incrementing updates and locks

From: Aras Angelo <araskoktas(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: incrementing updates and locks
Date: 2010-09-16 22:54:47
Message-ID: AANLkTinQ-A9oPExCgmwWv5br9+kmvnZVCBNhdLzED_qK@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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? Should i set the
MAX variable in a different table, and query that table and assign the next
value to the actual table every time there is an UPDATE going? That means a
SELECT to the max number holder table, UPDATE to the actual table, and an
UPDATE to the max_holder table again. That probably would slow down the
process but i cant think of a better way.

Lets say a client updates 30 in a batch, i dont think i can do one SELECT
max_number and increment that number with the programming language
independent from the DB because several clients access the database
synchronously.

Also should i be worried about LOCKING the tables, or UPDATE statements
already does a lock itself?

Sorry if i could not make it clear enough.

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Craig James 2010-09-16 23:06:32 Re: incrementing updates and locks
Previous Message Tom Lane 2010-09-16 15:14:35 Re: Bidirectional index traversal