pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mikhail V. Puzanov <misha.puzanov@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: atomic multi-threaded upsert
Date: Sat, 27 Nov 2010 21:08:39 +0600
Message-ID: <4CF11EF7.4020605@gmail.com> (raw)
In-Reply-To: <AANLkTi=_cTvvK=-fmnd1TNemVWUtMacrXJFUjuwrV3BG@mail.gmail.com>
References: <4CED72BB.3070905@gmail.com>
	<21822.1290633670@sss.pgh.pa.us>
	<AANLkTi=_cTvvK=-fmnd1TNemVWUtMacrXJFUjuwrV3BG@mail.gmail.com>

On 25.11.2010 12:51, MIkhail Puzanov wrote:
>
>
> 2010/11/25 Tom Lane <tgl@sss.pgh.pa.us <mailto:tgl@sss.pgh.pa.us>>
>
>     "Mikhail V. Puzanov" <misha.puzanov@gmail.com
>     <mailto:misha.puzanov@gmail.com>> writes:
>     >    -- increment and get the counter if exists
>     >   UPDATE sequences SET counter = counter + 1
>     >   WHERE section = 'testSection' AND name = 'testKey'
>     >   RETURNING counter;
>
>     Seems that what you have here is a bad manual implementation of a
>     sequence.  Why don't you use a real sequence object and nextval()?
>
>
>
> Well, if I use the real sequence, I'll need unpredictable number of them
> and will have to store mapping (section, name)->sequenceName, and
> also will have to create those sequences dynamically the similar way.
>

Finally the problem solved with application level locks (that works for
only
one application server, but suits our needs for now).

This also works
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE
but we need some more or less cross-DBMS approach.

view thread (6+ messages)

Message-ID: <4CF11EF7.4020605@gmail.com>
Permalink:  ../4CF11EF7.4020605@gmail.com/
Also on:    postgresql.org/message-id/4CF11EF7.4020605@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: misha.puzanov@gmail.com
  Subject: Re: atomic multi-threaded upsert
  In-Reply-To: <4CF11EF7.4020605@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox