Make Sqlalchemy Use Date In Filter Using Postgresql

后端 未结 4 1883
广开言路
广开言路 2021-02-05 05:32

I\'m trying to perform the following query in Sqlalchemy.

Select * from \"Mytable\" where Date(date_time_field) = \"2011-08-16\";

I have tried

4条回答
  •  遇见更好的自我
    2021-02-05 05:38

    Using @Ants Aasma Comment.

    And to Keep it clean for any web search.

    from sqlalchemy import Date, cast
    from datetime import date
    
    my_data = session.query(MyObject).\
    filter(cast(MyObject.date_time,Date) == date.today()).all()
    

    Thank you all who tried to solve this problem :)

提交回复
热议问题