I’m trying to perform the following query in Sqlalchemy.
JavaScript
x
2
1
Select * from "Mytable" where Date(date_time_field) = "2011-08-16";
2
I have tried several methods. Some here on SO. But none seems “realistic” since some do Casts Other String Formating ?!?! and not a plain simple Date() ( By Date i Mean the Postgresql Date not the Python One) at the ORM Field.
Is it possible at the ORM level to declare a Simple Date()
around the queried field?
Advertisement
Answer
To keep it clean for any web search.
JavaScript
1
6
1
from sqlalchemy import Date, cast
2
from datetime import date
3
4
my_data = session.query(MyObject).
5
filter(cast(MyObject.date_time,Date) == date.today()).all()
6