but I’m with Sven here, you should use sequences (unless there is something that prevents you to do it… ?).
Esteban On 17 Apr 2014, at 11:50, [email protected] wrote: > I think this is simply a case of optimistic locking - there is a general > way and very often db specific ways > > first you get the current active value ... (one row) > > currentValue from "select counterfield from tablename" > > > then you update the table (single row) > > > update > tablename > set > counterfield = currentValue + 1 > where > counterfield = currentValue > > commit > > then you look how many rows have been changed (=1) and assume, that > commit was successful and then you know if you were successful ... > otherwise you must retry ... > > this is a simple, with worst performance but portale approach ... > > Marten > > > Am 16.04.2014 21:52, schrieb Esteban A. Maringolo: >> Hi, >> >> A few weeks ago Sven was asking for a lock-free in-image atomic counter. >> >> Today I'm in need of implementing a DB backed (PGSQL) counter for >> business forms numbering, and maybe there are some toughts you're >> willing to share :) >> >> I can't find any other way than a row lock for each counter, but maybe >> there is something better (I avoid locks as much as possible). >> >> Any thoughts to share here? >> >> Regards! >> > > > -- > Marten Feldtmann >
