Re: MERGE and parsing with prepared statements

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: MERGE and parsing with prepared statements
Date: 2022-07-18 13:20:00
Message-ID: 20220718132000.GB18011@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 15, 2022 at 03:43:41PM -0500, Justin Pryzby wrote:
> Should that sentence be removed from MERGE ?

Also, I think these examples should be more similar.

doc/src/sgml/ref/merge.sgml

> <programlisting>
> MERGE INTO CustomerAccount CA
> USING RecentTransactions T
> ON T.CustomerId = CA.CustomerId
> WHEN MATCHED THEN
> UPDATE SET Balance = Balance + TransactionValue
> WHEN NOT MATCHED THEN
> INSERT (CustomerId, Balance)
> VALUES (T.CustomerId, T.TransactionValue);
> </programlisting>
> </para>
>
> <para>
> Notice that this would be exactly equivalent to the following
> statement because the <literal>MATCHED</literal> result does not change
> during execution.
>
> <programlisting>
> MERGE INTO CustomerAccount CA
> USING (Select CustomerId, TransactionValue From RecentTransactions) AS T
> ON CA.CustomerId = T.CustomerId
> WHEN NOT MATCHED THEN
> INSERT (CustomerId, Balance)
> VALUES (T.CustomerId, T.TransactionValue)
> WHEN MATCHED THEN
> UPDATE SET Balance = Balance + TransactionValue;
> </programlisting>
> </para>

The "ON" lines can be the same.
The "MATCHED" can be in the same order.

--
Justin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2022-07-18 13:24:02 limits of max, min optimization
Previous Message Justin Pryzby 2022-07-18 13:13:29 Re: Commitfest Update