Re: question on most efficient way to increment a column - Mailing list pgsql-general

From Tyson Maly
Subject Re: question on most efficient way to increment a column
Date
Msg-id 1368040479.39722.androidMobile@web120505.mail.ne1.yahoo.com
Whole thread Raw
In response to question on most efficient way to increment a column  (Tyson Maly <tvmaly@yahoo.com>)
Responses Re: question on most efficient way to increment a column  (Alban Hertroys <haramrae@gmail.com>)
List pgsql-general

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;

Yours,
Laurenz Albe


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Does it make sense to break a large query into separate functions?
Next
From: ning chan
Date:
Subject: Trigger function on Warm Standby