You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SQLAlchemy (ORM) land, the standard is that the cursor object provides inserted_primary_key and lastrowid attributes. However, currently, both of them do not return anything sensible.
dataset uses SQLAlchemy's inserted_primary_key attribute for returning the pk value from its insert method, see https://github.com/pudo/dataset/blob/1.5.2/dataset/table.py#L120-L121. It is important to make this work in order to be able to reference records just inserted, for manipulating them later, or for referencing them elsewhere.
Other statements
.inserted_primary_key returns a tuple of the primary key of the single inserted row using the connection.execute() command. A good reason to use .inserted_primary_key instead of .lastrowid: .lastrowid is database specific, it may work for some databases while not for others. But .inserted_primary_key will always work regardless of the underlying database.
amotl
changed the title
Provide autogenerated primary key value for the row just inserted via DBAPI's lastrowid and SQLAlchemy's inserted_primary_key attributes
Populate primary key value for the row just inserted into DBAPI's lastrowid and SQLAlchemy's inserted_primary_key attributes
Mar 6, 2023
Problem
In SQLAlchemy (ORM) land, the standard is that the cursor object provides
inserted_primary_key
andlastrowid
attributes. However, currently, both of them do not return anything sensible.Motivation
dataset
uses SQLAlchemy'sinserted_primary_key
attribute for returning the pk value from itsinsert
method, see https://github.com/pudo/dataset/blob/1.5.2/dataset/table.py#L120-L121. It is important to make this work in order to be able to reference records just inserted, for manipulating them later, or for referencing them elsewhere.Other statements
The text was updated successfully, but these errors were encountered: