Ah, I was completely unaware of tuple_(). That's what I was looking for. 
Thanks!

keskiviikko, 18. joulukuuta 2013 18.31.42 UTC+2 Michael Bayer kirjoitti:
>
>
> On Dec 17, 2013, at 8:39 PM, Alex Grönholm 
> <alex.g...@nextday.fi<javascript:>> 
> wrote:
>
> I would like to check if two date ranges overlap. This is done using the 
> OVERLAPS 
> operator<http://www.postgresql.org/docs/9.2/static/functions-datetime.html>
> .
> 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+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.

Reply via email to