On 2010-11-24, "Mikhail V. Puzanov" <
misha.puzanov@gmail.com> wrote:
> Next, I execute the following two queries for that table:
>
> -- increment and get the counter if exists
> UPDATE sequences SET counter = counter + 1
> WHERE section = 'testSection' AND name = 'testKey'
> RETURNING counter;
>
> -- insert new counter if not exists
> INSERT INTO sequences ( section, name, counter )
> SELECT 'testSection', 'testKey', 0
> WHERE NOT EXISTS (
> SELECT * FROM sequences
> WHERE section = 'testSection' AND name = 'testKey'
> );