I have table in sqlalchemy 0.4 that with types.DateTime column:
Column("dfield", types.DateTime, index=True)
I want to select records, that has specific year in this column, using model. How to do this? I though it should be done like this:
selected_year = 2009
my_session = model.Session()
my_query = my_session.query(model.MyRecord).filter(model.dfield.??? == selected_year)
# process data in my_query
Part with ??? is for me unclear.
sqlalchemy.extract('year', model.MyRecord.dfield) == selected_year
对于referene: https ://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.extract
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.