This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients erlendaasland, lemburg
Date 2022-01-04.10:45:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <9a6e5d8e-629d-d6ee-a517-3c7080391e43@egenix.com>
In-reply-to <1641290575.89.0.719199526838.issue46249@roundup.psfhosted.org>
Content
On 04.01.2022 11:02, Erlend E. Aasland wrote:
> 
> Erlend E. Aasland <erlend.aasland@innova.no> added the comment:
> 
> Thank you for your input Marc-André.
> 
> For SQLite, it's pretty simple: we use an API called sqlite3_last_insert_rowid() which takes the database connection as it's argument, not a statement pointer. This function returns "the rowid of the most recent successful INSERT into a rowid table or virtual table on database connection" (quote from SQLite docs). IMO, it would make sense to also use this post executemany().

Sounds like a plan.

If possible, it's usually better to have the .executemany() create a
cursor with an output array providing the row ids, e.g. using "INSERT ...
RETURNING ..." (PostgreSQL). That way you can access all row ids and
can also provide the needed detail in case the INSERTs happen out of
order to map them to the input data.

For cases where you don't need sequence IDs, it's often better to
not rely on auto-increment columns for IDs, but instead use random
pre-generated IDs. Saves roundtrips to the database and works nicely
with cluster databases as well.
History
Date User Action Args
2022-01-04 10:45:50lemburgsetrecipients: + lemburg, erlendaasland
2022-01-04 10:45:50lemburglinkissue46249 messages
2022-01-04 10:45:50lemburgcreate