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)