[Sqlalchemy-tickets] Issue #3353: combination of and_() and or_() produces unexpected sql output (z
Brought to you by:
zzzeek
|
From: petergrace <iss...@bi...> - 2015-04-03 15:46:37
|
New issue 3353: combination of and_() and or_() produces unexpected sql output https://bitbucket.org/zzzeek/sqlalchemy/issue/3353/combination-of-and_-and-or_-produces petergrace: For the given filter spec, the sql generated does not match what I would expect to see: ``` #!python .filter(or_( \ and_(func.len(ExtendedCDR.Source) > 6, ExtendedCDR.DestinationContext=='ael-outbound-dial'), \ and_(func.len(ExtendedCDR.Destination)>6,ExtendedCDR.DestinationContext=='ael-std-extension') \ ) \ ``` This produces: ``` #!sql (len(cdr_extended.[Source]) > ? AND cdr_extended.[DestinationContext] = ? OR len(cdr_extended.[Destination]) > ? AND cdr_extended.[DestinationContext] = ?) ``` Note only a single set of parantheses wrapping the logic, whereas I would expect to see: ``` #!sql ( (len(cdr_extended.[Source]) > ? AND cdr_extended.[DestinationContext] = ?) OR (len(cdr_extended.[Destination]) > ? AND cdr_extended.[DestinationContext] = ?) ) ``` If I am misunderstanding how and_ and or_ are supposed to work together, can you set me straight, or alternatively let me know how I can cause sqlalchemy to emit the query with the proper order of operations? |