Re: Merge into does not work

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Merge into does not work
Date: 2021-11-26 19:44:36
Message-ID: 202111261944.siaofq7of32m@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2021-11-26 20:07:49 Re: Merge into does not work
Previous Message Tom Lane 2021-11-26 19:44:29 Re: What do you do with a long running rollback