I am using pd.read_sql()
together with SQL alchemy. However, it is not using the attribute name of the mapping for the columns in the pandas dataframe, but the original SQL column name:
class DBtable(Base):
name: mapped_column("firstname")
So in such case, after calling
stmt = select(DBTable)
df = pd.read_sql(stmt, engine)
I would get a df with 'firstname' as the column name.
I use a work around by using column_property
, but is there maybe a nicer way to achieve this?
class DBtable(Base):
name: Mapped[str] = column_property(mapped_column("firstname"))
I don't want to use the alias inside the query or rename the dataframe column later, as this renaming should be transparent to the user and the goal is to unify naming across several tables and databases...
name: Mapped[str] = mapped_column("firstname")