Re: question on most efficient way to increment a column

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: Tyson Maly <tvmaly(at)yahoo(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: question on most efficient way to increment a column
Date: 2013-05-08 14:02:58
Message-ID: A737B7A37273E048B164557ADEF4A58B05818F07@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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;

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-05-08 14:05:17 Re: Does it make sense to break a large query into separate functions?
Previous Message Merlin Moncure 2013-05-08 14:02:34 Re: question on most efficient way to increment a column