Re: Merge into does not work - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Merge into does not work
Date
Msg-id 202111261944.siaofq7of32m@alvherre.pgsql
Whole thread Raw
In response to Merge into does not work  (Shaozhong SHI <shishaozhong@gmail.com>)
Responses Re: Merge into does not work
List pgsql-general
On 2021-Nov-26, Shaozhong SHI wrote:

> MERGE INTO Stock USING Buy ON Stock.item_id = Buy.item_id
>  WHEN MATCHED THEN UPDATE SET balance = balance + Buy.volume
>  WHEN NOT MATCHED THEN INSERT VALUES (Buy.item_id, Buy.volume);

It does work for me:

55479 15devel 680346=# MERGE INTO Stock USING Buy ON Stock.item_id = Buy.item_id
 WHEN MATCHED THEN UPDATE SET balance = balance + Buy.volume
 WHEN NOT MATCHED THEN INSERT VALUES (Buy.item_id, Buy.volume);
MERGE 2
Duración: 3,879 ms
55479 15devel 680346=# select * from stock;
 item_id │ balance 
─────────┼─────────
      20 │    1900
      10 │    3200
      30 │     300
(3 filas)

> I am using Postgres 9.6.

I am using the MERGE patch I posted here[1], on top of Postgres 15.

https://postgr.es/m/202111152245.byerxxac444d@alvherre.pgsql

-- 
Álvaro Herrera              Valdivia, Chile  —  https://www.EnterpriseDB.com/
"Pido que me den el Nobel por razones humanitarias" (Nicanor Parra)



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: What do you do with a long running rollback
Next
From: Adrian Klaver
Date:
Subject: Re: Merge into does not work