Thank you for your reply Jonathan. I tried your suggestion and tested the
effect of adding .compile statements. I think it provides some insight into
my point #2, i.e. different results when I run the literal bound query vs.
when I run the unbound expression. Point #1, i.e. the lack of parentheses
around the negated expression, still stands.

I actually used SQLite in my gist example to avoid forcing anything to
install mysql, so I experimented with .compile using both a mysql engine
and a SQLite engine. The results are similar: they both output queries like

SELECT user.user_id, user.user_name, user.email_address, user.password
FROM user
WHERE user.user_name = ? OR user.user_name = ? = 0


instead of the


SELECT "user".user_id, "user".user_name, "user".email_address, "user".password

FROM "user"

WHERE NOT "user".user_name = 'jack' OR "user".user_name = 'james'


that I get by using str() without .compile()


As you can see, the dialect used changes where the NOT expression
appears in the query (i.e. NOT "user".user_name = 'jack' vs. OR
user.user_name = ? = 0). Because the negation doesn't have
parentheses, that means that in one case the first condition is
negated and in the other the second condition is negated, producing
logically different results.


To me, that suggests that the emitted query should have parentheses
regardless of the dialect used.



On Thu, Apr 20, 2017 at 3:48 PM, Jonathan Vanasco <[email protected]>
wrote:

> i briefly glanced at your setup, and just want to note that you'll have a
> better comparison using the `compile` with the mysql engine (docs here:
> http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html)
>
> the query clauses you pass into `str()` aren't compiled for the mysql
> dialect, so may differ from what is being emitted.
>
> this might not change the output of your test case, but it often does --
> and may help you realize the answer.  (or Mike/Simon may chime in before
> then)
>
> --
> 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 a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/sqlalchemy/LfYF4W3CV4U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to