What we are starting to support now, which we currently support for psycopg2
only but will be adding more support soon, is a single INSERT with VALUES and
RETURNING, we can then get all the autogenned primary keys back in the result
set for a single INSERT statement that has multiple rows
Mike, thank you very much for this very thorough answer. I now understand
that my use case cannot be generally supported by SQLAlchemy, given the
limitations of the backends.
Yet, I still wonder how to efficiently perform inserts of large numbers of
rows where the server-generated ids are
So the use case you are doing there was never something supported, and in
particular the value you are getting on 1.3 is not really universally reliable,
as it is relying upon cursor.lastrowid that is not defined for multiple-row
inserts, even though for InnoDB specifically the behavior is
I use SQLAlchemy with MySQL. In one application, I need to obtain the
server-generated primary key values of newly inserted rows by obtaining the
value of the first inserted row with the property inserted_primary_key.
However, after upgrading to version 1.4.15, this property return only