Re: remove upsert example from docs - Mailing list pgsql-hackers

From Tom Lane
Subject Re: remove upsert example from docs
Date
Msg-id 27688.1281034408@sss.pgh.pa.us
Whole thread Raw
In response to Re: remove upsert example from docs  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-hackers
Merlin Moncure <mmoncure@gmail.com> writes:
> On Thu, Aug 5, 2010 at 2:09 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I was not persuaded that there's a real bug in practice. �IMO, his
>> problem was a broken trigger not broken upsert logic. �Even if we
>> conclude this is unsafe, simply removing the example is of no help to
>> anyone.

> Well, the error handler is assuming that the unique_volation is coming
> from the insert made within the loop.  This is obviously not a safe
> assumption in an infinite loop context.

Well, that's a fair point.  Perhaps we should just add a note that if
there are any triggers that do additional inserts/updates, the exception
catcher had better check which table the unique_violation is being
reported for.

>> A more useful response would be to supply a correct example.

> Agree: I'd go further I would argue to supply both the 'safe' and
> 'high concurrency (with caveat)' way.  I'm not saying the example is
> necessarily bad, just that it's maybe not a good thing to be pointing
> as a learning example without qualifications.  Then you get a lesson
> both on upsert methods and defensive error handling (barring
> objection, I'll provide that).

Have at it.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: Drop one-argument string_agg? (was Re: [BUGS] string_agg delimiter having no effect with order by)
Next
From: Josh Berkus
Date:
Subject: Re: Drop one-argument string_agg? (was Re: [BUGS] string_agg delimiter having no effect with order by)