Repository navigation
Use RETURNING to report single-insert primary keys - #958
Open
businessdeveloper69 wants to merge 1 commit into
Open
businessdeveloper69 wants to merge 1 commit into
businessdeveloper69 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #359.
A single insert into a
WITHOUT ROWIDtable can returnlast_pk == 0or raiseOperationalError: no such column: rowidafter the row has already committed. Which result you get depends on whether an earlier insert on the same connection set a rowid.This uses
INSERT … RETURNINGon SQLite 3.35+ to get the inserted key when supported. It returns single and composite keys fromWITHOUT ROWIDtables and leaveslast_rowidunset. Ordinary tables with triggers retain their post-insert lookup. ForWITHOUT ROWID, the docs explain that the returned key precedes any changes made by anAFTERtrigger. Older SQLite versions keep the existing path.Four on-disk reproductions covered fresh connections and connections with a prior rowid, each with single and composite keys. In every case the returned key retrieved the stored row. A SQL trace on an existing ordinary table showed six statements before and after for the default rowid case, and thirteen before versus eleven after for an explicit text key.
The full Python 3.12 and Python 3.14 autocommit runs each passed 1,510 tests with 13 skips. A real SQLite 3.23.1 compatibility run passed 252 with 10 skips. Formatting, flake8, mypy, Pyright, documentation and CLI checks passed.
ty0.0.107 reported the same redundant cast in existing list-mode code on both the upstream base and this commit.AI assisted.
📚 Documentation preview 📚: https://sqlite-utils--958.org.readthedocs.build/en/958/