Allow sqlite-utils upsert to infer --pk from existing table

This commit is contained in:
Simon Willison 2026-07-07 18:09:12 -07:00
commit ebafb84c93
4 changed files with 30 additions and 6 deletions

View file

@ -321,6 +321,8 @@ See :ref:`cli_upsert`.
incoming record has a primary key that matches an existing record the existing
record will be updated.
If the table already exists and has a primary key, --pk can be omitted.
Example:
echo '[
@ -330,7 +332,6 @@ See :ref:`cli_upsert`.
Options:
--pk TEXT Columns to use as the primary key, e.g. id
[required]
--flatten Flatten nested JSON objects, so {"a": {"b": 1}}
becomes {"a_b": 1}
--nl Expect newline-delimited JSON

View file

@ -1593,6 +1593,8 @@ For example:
This will update the dog with an ID of 2 to have an age of 4, creating a new record (with a null name) if one does not exist. If a row DOES exist the name will be left as-is.
If the table already exists and has a primary key, you can omit the ``--pk`` option and ``sqlite-utils`` will use that existing primary key.
The command will fail if you reference columns that do not exist on the table. To automatically create missing columns, use the ``--alter`` option.
.. note::