Does anyone know what the syntax for using DateRanges is?

I'm trying to find out if a given date falls within a range, and so thought 
that the `in` syntax in Python might work (to no avail):

from psycopg2.extras import DateRange
session.query(Order).filter(Order.created_at in DateRange(d1, d2, '[]'))

I then realised I was using incorrect types for this, and so cast my 
DATETIME column to a DATE:

session.query(Order).filter(cast(Order.created_at, DATE) in DateRange(d1, 
d2, '[]'))

However this also doesn't work, and throws the exception `TypeError: 
Boolean value of this clause is not defined`

I did manage to get it working, but the syntax is clunky, and so was 
wondering if there's something I'm missing.

session.query(Order).filter(cast(Order.created_at, 
DATE).op('<@')(DateRange(d1, d2, '[]')))

which explicitly uses the ' contained by' operator.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to