Re: MERGE examples not clear

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: dwayne(dot)towell(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: MERGE examples not clear
Date: 2023-02-21 15:56:50
Message-ID: CAKFQuwZrP1_hRLT8JXdfX4Bi20-Y3oGPsaKeRVe9bNzngFP+JQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Tue, Feb 21, 2023 at 8:35 AM PG Doc comments form <noreply(at)postgresql(dot)org>
wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/15/sql-merge.html
> Description:
>
> On this page: https://www.postgresql.org/docs/15/sql-merge.html
> the first and second examples seems to be contrasted (by "this would be
> exactly equivalent to the following statement"), however the difference
> does
> not seem to related to the stated reason ("the MATCHED result does not
> change"). It seems like the difference should involve the order of WHEN
> clauses?
> Of course, it might be that I don't understand the point, in which case
> maybe the point could be stated more clearly?
>

Yeah, that is a pretty poor pair of examples. Given that a given customer
can reasonably be assumed to have more than one recent transaction the
MERGE has a good chance of failing.

The only difference between the two is the second one uses an explicit
subquery as the source while the first simply names a table. If the
subquery had a GROUP BY customer_id that would be a good change explaining
that the second query is different because it is resilient in the face of
duplicate customer recent transactions.

While here...source_alias (...completely hides...the fact that a query was
issued). What? Probably it should read (not verified) that it is actually
required when the source is a query (maybe tweaking the syntax to match).

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Geoghegan 2023-02-21 17:46:29 Re: Transaction wraparound and read committed isolation level
Previous Message PG Doc comments form 2023-02-21 15:14:17 MERGE examples not clear