On Dec 17, 2013, at 8:39 PM, Alex Grönholm <alex.gronh...@nextday.fi> wrote:
> I would like to check if two date ranges overlap. This is done using the > OVERLAPS operator. > For example: > > SELECT (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS > (DATE '2001-10-30', DATE '2002-10-30'); > > How do I do this in SQLAlchemy? I have no clue how to produce the parentheses > here. I think what we’re really looking at are two tuples, so might as well use that: >>> from sqlalchemy import create_engine, tuple_, select >>> import datetime >>> e = create_engine("postgresql://scott:tiger@localhost/test", echo=True) >>> s = select([ ... tuple_(datetime.date(2001, 2, 6), datetime.date(2001, 12, 21)).op('overlaps')( ... tuple_(datetime.date(2001, 10, 30), datetime.date(2002, 10, 30))) ... ]) >>> e.scalar(s) 2013-12-18 11:30:05,232 INFO sqlalchemy.engine.base.Engine SELECT (%(param_1)s, %(param_2)s) overlaps (%(param_3)s, %(param_4)s) AS anon_1 2013-12-18 11:30:05,232 INFO sqlalchemy.engine.base.Engine {'param_4': datetime.date(2002, 10, 30), 'param_1': datetime.date(2001, 2, 6), 'param_3': datetime.date(2001, 10, 30), 'param_2': datetime.date(2001, 12, 21)} True > > -- > 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 http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/groups/opt_out.
signature.asc
Description: Message signed with OpenPGP using GPGMail