On Jan 27, 2009, at 6:14 PM, Jon Nelson wrote:

>
> I recently ran into an issue. Is it a bug? No. However, it made my
> brain hurt for a little bit until I remembered the SQL precedence
> rules for AND and OR.
>
> The operator precedence of AND and OR is known (AND takes precedence).
> However, it can make humans hurt their brains a bit to see SQL without
> (perhaps unnecessary) parens, explicitly noting the desired order of
> operation. Perhaps a suggestion might be to always use parens?
>
> Approx. line 2168 of sql/expression.py:
>
>        if self.group and self.operator is not against and
> operators.is_precedent(self.operator, against):
>
> What would the harm be in removing the final test (and
> operators.is_predecent...) ?
>
>
> It seems to me that SQLAlchemy might group things a bit more
> explicitly instead of relying on the precedence rules. Are there
> database which have precedence rules that are not the same as others
> (or are buggy)?

well some databases react poorly to excessive parenthesis.  Sqlite  
can't handle a phrase like select * from x join (y join z) for  
example, lots of DB's don't like to see ((a and b)) types of  
expressions either.

if it makes you feel any better, I didn't write the full precedence  
code myself, came across an expression that was just  A AND B OR C and  
i thought it was a bug for awhile.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to