SQLite User Forum

MERGE statement?
Login

MERGE statement?

(1) By anonymous on 2022-04-01 21:05:49 [link] [source]

Hello,

Now that the upcoming PostgreSQL 15 sports a MERGE statement, would SQLite follow suit?

https://www.depesz.com/2022/03/31/waiting-for-postgresql-15-add-support-for-merge-sql-command/

https://www.postgresql.org/docs/devel/sql-merge.html

https://en.wikipedia.org/wiki/Merge_(SQL)

(2) By Marco Bubke (marcob) on 2022-04-01 21:49:15 in reply to 1 [link] [source]

AFAIK SQL Server has a similar feature.

Actually I found a way to implement a similar feature in Sqlite as you can delete, insert and delete as you select a statement. You only need to sort the select and the data which you want to merge in the same order. There are some side effects which are documented. I put that in an C++ algorithm which then gets the data and the select, insert, update and delete as parameter. The algorithm iterates over both sequences and compares them. This works fine but I think a sqlite function still could optimize it.

(3) By Yair lenga (Yairlenga) on 2022-05-23 03:38:09 in reply to 1 [source]

+1.

It’s will close a big gap in term of using same DDL across databases. Almost all multi-database applications (and abstraction libraries) avoided MERGE because it was not available for Postgresql. If SQLite will follow Postgresql, MERGE will becomes a standard, and eliminate the need for database specific multi table updates.