I know I can lazy load columns from a table:
session.query(MyTable).options(defer(colname)
for colname in ['col4', 'col5', .., 'colN'])
I only want the first 3 columns, so can shorten that to the following:
session.query(MyTable).options(defer(col.name)
for col.name in MyTable.__table__.columns
if col.name not in ['col1', 'col2', 'col3'])
Because MyTable has a few extra column_propertys which aren't listed in MyTable.__table__.columns, these get included in the query even though I don't want them.
So is there a construct to express what I want directly as a restriction? e.g. something like
session.query(MyTable).options(XXselect('col1', 'col2', 'col3'))
If you only want the values, you can just call :
session.query(Mytable.col1, MyTable.col2, MyTable.col3).
If you want the full object with deferred columns, MyTable.__table__.columns should give you all the columns regardless of the mixins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With