[Dbix-class] Re: Accumulating totals in a column

Bill Moseley moseley at hank.org
Wed Jun 13 20:29:51 GMT 2012


Eh, "custom result source" not "customer result set."

On Wed, Jun 13, 2012 at 3:24 PM, Bill Moseley <moseley at hank.org> wrote:

> Say I have a table "task" in a Postgresql database that has an integer
> column "total_seconds" which is a total number of seconds one or more
> actors (people, worker processes, etc.) spent working on the task.   So,
> these various actors need to add some value to an existing column.
>
> What is the recommended way to to add to an existing integer column like
> this and avoid race condition?
>
> I can see in the past I've used a customer result set:
>
>     UPDATE task SET total_seconds =3D total_seconds + ? WHERE id =3D ?
>
> but, I also have used  SELECT .. FOR UPDATE  ( i.e. { for =3D> 'update' }=
 )
> in a transaction.
>
>  Is there any advantage of one over the other?
>
>
> --
> Bill Moseley
> moseley at hank.org
>



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120613/896=
47793/attachment.htm


More information about the DBIx-Class mailing list