On Sat, 16 Nov 2013 17:19:06 +0100, Petite Abeille
<petite.abei...@gmail.com> wrote:

>
>On Nov 16, 2013, at 4:11 PM, James K. Lowden <jklow...@schemamania.org> wrote:
>
>> The logical equivalent of MERGE is accomplished by one INSERT and one
>> UPDATE inside a user-defined transaction.  Given SQLite's locking
>> semantics, it's atomic.  Nothing procedural about it.  
>
>Well, one would still need to wrap these transaction and branching in some 
>kind of procedural code. So procedural it is.

A possible solution might be:

Create a VIEW "merge_t" on the table "t" you want to merge into.

Create an INSTEAD OF TRIGGER that handles the gory details of
INSERT OR IGNORE INTO t .... ;
UPDATE t set ....

For the application, the merge would look like a single
INSERT INTO merge_t statement.

(untested)

Remark: The view and the trigger are pretty straightforward, and the SQL
could probably be generated by a smart m4 macro.

-- 
Groet, Cordialement, Pozdrawiam, Regards,

Kees Nuyt

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to