The simple update is one I considered, but I think if I put it into a stored procedure it should run faster
From: Albe Laurenz <laurenz.albe@wien.gv.at>; To: Tyson Maly <tvmaly@yahoo.com>; pgsql-general@postgresql.org <pgsql-general@postgresql.org>; Subject: Re: [GENERAL] question on most efficient way to increment a column Sent: Wed, May 8, 2013 2:02:58 PM
Tyson Maly wrote: > If I have a simple table with an id as a primary key that is a serial column and a column to keep > track of a total_count for a particular id, what method would provide the fastest way to increment the > total_count in the shortest amount of time and minimize any locking? > > id serial > total_count integer
UPDATE tablename SET total_count=total_count+1 WHERE id=42;