Skip to content

Commit 8e7d018

Browse files
authored
Use ON CONFLICT for upsert, refs #652
* New upsert implementation, refs #652 * supports_strict now caches on self._supports_strict PR: #653
1 parent 72f6c82 commit 8e7d018

File tree

7 files changed

+209
-110
lines changed

7 files changed

+209
-110
lines changed

docs/python-api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,13 @@ An ``upsert_all()`` method is also available, which behaves like ``insert_all()`
927927
.. note::
928928
``.upsert()`` and ``.upsert_all()`` in sqlite-utils 1.x worked like ``.insert(..., replace=True)`` and ``.insert_all(..., replace=True)`` do in 2.x. See `issue #66 <https://github.com/simonw/sqlite-utils/issues/66>`__ for details of this change.
929929

930+
.. _python_api_old_upsert:
931+
932+
Alternative upserts using INSERT OR IGNORE
933+
------------------------------------------
934+
935+
Upserts use ``INSERT INTO ... ON CONFLICT SET``. Prior to ``sqlite-utils 4.0`` these used a sequence of ``INSERT OR IGNORE`` followed by an ``UPDATE``. This older method is still used for SQLite 3.23.1 and earlier. You can force the older implementation by passing ``use_old_upsert=True`` to the ``Database()`` constructor.
936+
930937
.. _python_api_convert:
931938

932939
Converting data in columns

sqlite_utils/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,9 @@ def insert_upsert_implementation(
10981098
if (
10991099
isinstance(e, OperationalError)
11001100
and e.args
1101-
and "has no column named" in e.args[0]
1101+
and (
1102+
"has no column named" in e.args[0] or "no such column" in e.args[0]
1103+
)
11021104
):
11031105
raise click.ClickException(
11041106
"{}\n\nTry using --alter to add additional columns".format(

0 commit comments

Comments
 (0)