pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lincoln Yeoh <lyeoh@pop.jaring.my>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: jhondius@rem.nl
Cc: Pau Marc Muñoz Torres <paumarc@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: conditional insert
Date: Wed, 07 Sep 2011 23:45:11 +0800
Message-ID: <20110907154526.AF909B5D80A@mail.postgresql.org> (raw)
In-Reply-To: <CAHyXU0x3jMadwoZFW8S5+g04VjBGURNUnEYN4ZzhmAy5CQaTGw@mail.g mail.com>
References: <CADFuJLjCF6fmxswgS033EFyofmbJFy+J0ToUvwTCDDLYj+nr3Q@mail.gmail.com>
	<j4261h$lj8$1@dough.gmane.org>
	<CADFuJLi3K0X1A7OwR+9_neWjKCEXtYYyMP_n=x5z=D2+GNCTNw@mail.gmail.com>
	<4E64A79E.7030503@compulab.co.il>
	<CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.com>
	<4E64AC45.6030704@rem.nl>
	<20110906190548.433E8B5DBD1@mail.postgresql.org>
	<CAHyXU0zSE4aVoZhXL9i8hnSjRaJwOpmcrV+jfLKKY=OCdXhR6A@mail.gmail.com>
	<CAHyXU0x3jMadwoZFW8S5+g04VjBGURNUnEYN4ZzhmAy5CQaTGw@mail.gmail.com>

At 05:23 AM 9/7/2011, Merlin Moncure wrote:
>On Tue, Sep 6, 2011 at 3:45 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
>
> > b) doesn't block reads if you lock in EXCLUSIVE mode.  a) is the best
> > way to go if you prefer to handle errors on the client and/or
> > concurrency is important...c) otherwise.
>
>whoops!  meant to say b) otherwise! As far as c) goes, that is
>essentially an advisory lock for the purpose -- using advisory locks
>in place of mvcc locks is pretty weak sauce -- they should be used
>when what you are locking doesn't follow mvcc rules.
>
>merlin

Don't you have to block SELECTs so that the SELECTs get serialized? 
Otherwise concurrent SELECTs can occur at the same time, find no 
existing rows, then "all" the inserts proceed and you get errors (or dupes).

That's how Postgresql still works right? I haven't really been keeping up.

 From what I see this (UPSERT/MERGE) has been a common problem/query 
over the years but it's not in a Postgresql FAQ and many people seem 
to be using methods that don't actually work. Google shows that many 
are even recommending those methods to others. Postgresql might still 
get blamed for the resulting problems.

Regards,
Link.






view thread (36+ messages)  latest in thread

Message-ID: <20110907154526.AF909B5D80A@mail.postgresql.org>
Permalink:  ../20110907154526.AF909B5D80A@mail.postgresql.org/
Also on:    postgresql.org/message-id/20110907154526.AF909B5D80A@mail.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: lyeoh@pop.jaring.my, mmoncure@gmail.com, jhondius@rem.nl, paumarc@gmail.com
  Subject: Re: conditional insert
  In-Reply-To: <20110907154526.AF909B5D80A@mail.postgresql.org>
  References: <CADFuJLjCF6fmxswgS033EFyofmbJFy+J0ToUvwTCDDLYj+nr3Q@mail.gmail.com> <j4261h$lj8$1@dough.gmane.org> <CADFuJLi3K0X1A7OwR+9_neWjKCEXtYYyMP_n=x5z=D2+GNCTNw@mail.gmail.com> <4E64A79E.7030503@compulab.co.il> <CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.com> <4E64AC45.6030704@rem.nl> <20110906190548.433E8B5DBD1@mail.postgresql.org> <CAHyXU0zSE4aVoZhXL9i8hnSjRaJwOpmcrV+jfLKKY=OCdXhR6A@mail.gmail.com> <CAHyXU0x3jMadwoZFW8S5+g04VjBGURNUnEYN4ZzhmAy5CQaTGw@mail.gmail.com> <20110907154526.AF909B5D80A@mail.postgresql.org>

* 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