This is a static archive of the Python wiki, which was retired in February 2026 due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

Asking for Help: How can I fetch a system-generated value from a database after inserting a row using the cursor.execute() function?

The API is described in PEP 249. Unfortunately, the return value of cursor.execute is not defined in the specification, however, but it may be the case that your database adapter may provide a meaningful return value. When issuing insert statements in SQL, sometimes the number of rows inserted may be returned (which is probably what you're referring to), but even in systems like PostgreSQL where this can be observed, there can be situations where a result of 0 is given instead of the actual number of inserted rows. I seem to recall that table partitions, for instance, don't (or didn't) support non-zero results from insert when statements were issued in the SQL client. -- PaulBoddie 2012-05-31 12:03:22


CategoryAskingForHelp CategoryAskingForHelpAnswered


2026-02-14 16:06