Re: MERGE and parsing with prepared statements - Mailing list pgsql-hackers

From Justin Pryzby
Subject Re: MERGE and parsing with prepared statements
Date
Msg-id 20220718132000.GB18011@telsasoft.com
Whole thread Raw
In response to Re: MERGE and parsing with prepared statements  (Justin Pryzby <pryzby@telsasoft.com>)
List 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



pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Commitfest Update
Next
From: Pavel Stehule
Date:
Subject: limits of max, min optimization