Re: SQL MERGE patches for PostgreSQL Versions

From: Kang Yuzhe <tiggreen87(at)gmail(dot)com>
To: Jan de Visser <jan(at)de-visser(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, bxzhai2010(at)gmail(dot)com
Subject: Re: SQL MERGE patches for PostgreSQL Versions
Date: 2017-06-22 17:00:50
Message-ID: CAH=t1kpw0scMWRQpq-++dY7RU9CVRz1yN7THwEYNJjS++V=2NA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 22, 2017 at 7:52 PM, Jan de Visser <jan(at)de-visser(dot)net> wrote:
> On Thursday, June 22, 2017 12:32:14 PM EDT Kang Yuzhe wrote:
>> Here is a sample what I did after applying the patch.
>>
>> testdb=# BEGIN;
>> BEGIN
>> testdb=#
>> testdb=# MERGE INTO Stock USING Buy ON Stock.item_id = Buy.item_id
>> testdb-# WHEN MATCHED THEN UPDATE SET balance = balance + Buy.volume
>> testdb-# WHEN NOT MATCHED THEN DO NOTHING;
>> MERGE 1
>> testdb=# SELECT * FROM Stock;
>> item_id | balance
>> ---------+---------
>> 20 | 1900
>> 10 | 3200
>> (2 rows)
>>
>> testdb=# ROLLBACK;
>> ROLLBACK
>
> I am not quite sure what you're trying to achieve, but are you aware that
> pgsql 9.6 introduced the ON CONFLICT clause, which allows you to do the same
> with a different syntax?
>
> https://www.postgresql.org/docs/9.6/static/sql-insert.html
>
> Look for ON CONFLICT.

Yes, I am aware of ON CONFLICT.
DO NOTHING in SQL Merge is one type of scenario which is like ON CONFLICT.
My goal is to understand how SQL MERGE works which is in SQL ANSI/ISO
standard. And I would implement as a patch in the latest PG if I could
do that.

Regards,
Zeray.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kang Yuzhe 2017-06-22 17:08:14 Re: SQL MERGE patches for PostgreSQL Versions
Previous Message Jan de Visser 2017-06-22 16:52:13 Re: SQL MERGE patches for PostgreSQL Versions