SQLite - UPSERT *not* INSERT or REPLACE

后端 未结 18 3019
猫巷女王i
猫巷女王i 2020-11-21 23:53

http://en.wikipedia.org/wiki/Upsert

Insert Update stored proc on SQL Server

Is there some clever way to do this in SQLite that I have not thought of?

18条回答
  •  清歌不尽
    2020-11-22 00:21

    Beginning with version 3.24.0 UPSERT is supported by SQLite.

    From the documentation:

    UPSERT is a special syntax addition to INSERT that causes the INSERT to behave as an UPDATE or a no-op if the INSERT would violate a uniqueness constraint. UPSERT is not standard SQL. UPSERT in SQLite follows the syntax established by PostgreSQL. UPSERT syntax was added to SQLite with version 3.24.0 (pending).

    An UPSERT is an ordinary INSERT statement that is followed by the special ON CONFLICT clause

    Image source: https://www.sqlite.org/images/syntax/upsert-clause.gif

提交回复
热议问题