Re: [SQL] atomic multi-threaded upsert

2010-11-27 Thread Mikhail V. Puzanov
On 25.11.2010 12:51, MIkhail Puzanov wrote: > > > 2010/11/25 Tom Lane mailto:t...@sss.pgh.pa.us>> > > "Mikhail V. Puzanov" > writes: > >-- increment and get the counter if exists > > UPDATE sequences SET counter = counter + 1 > > WHERE se

Re: [SQL] atomic multi-threaded upsert

2010-11-24 Thread MIkhail Puzanov
2010/11/25 KM > On 2010-11-24, "Mikhail V. Puzanov" 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

Re: [SQL] atomic multi-threaded upsert

2010-11-24 Thread MIkhail Puzanov
2010/11/25 Tom Lane > "Mikhail V. Puzanov" 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

Re: [SQL] atomic multi-threaded upsert

2010-11-24 Thread KM
On 2010-11-24, "Mikhail V. Puzanov" 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

Re: [SQL] atomic multi-threaded upsert

2010-11-24 Thread Tom Lane
"Mikhail V. Puzanov" 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

[SQL] atomic multi-threaded upsert

2010-11-24 Thread Mikhail V. Puzanov
Hi, All I'm trying to make a kind of upsert for the following table: CREATE TABLE sequences ( section VARCHAR( 50 ) NOT NULL, name VARCHAR( 50 ) NOT NULL, counter BIGINT NOT NULL ); CREATE UNIQUE INDEX IDX_SEQUENCES_SN ON sequences(section, name); Next, I execute the following two