At a guess, I would say that the Python code "Foo.bar != bar" means that you 
are looking for Foo objects that aren't related to bar. This includes Foos that 
are related to a *different* Bar instance, as well as Foos that aren't related 
to *any* bar instance. In sql terms, foo.bar_id != bar.id OR foo.bar_id is NULL.

Whereas in the other instance, you've asked for something more specific, so 
that's what SA has given you.

Simon



> On 31 Oct 2014, at 16:36, Ladislav Lenart <lenart...@volny.cz> wrote:
> 
> Hello.
> 
> I have just noticed (by accident) a semantic difference of the not-equal
> operator (!=), depending on the style used. For example a query
> 
>    session.query(Foo).filter(Foo.bar_id != bar.id)
> 
> produces SQL like (expected)
> 
>    SELECT *
>    FROM foo
>    WHERE foo.bar_id != %(bar_id_1)s
> 
> whereas a query
> 
>    session.query(Foo).filter(Foo.bar != bar)
> 
> produces SQL like (NOT expected)
> 
>    SELECT *
>    FROM foo
>    WHERE (
>        foo.bar_id != %(bar_id_1)s
>        OR foo.bar_id IS NULL
>    )
> 
> I thought that
> 
>    Foo.bar != bar
> 
> is just a shortcut for
> 
>   Foo.bar_id != bar.id
> 
> Is this difference intentional?
> May I know why (i.e. the motivation)?
> 
> 
> Thanks in advance,
> 
> Ladislav Lenart
> 
> -- 
> 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/d/optout.

-- 
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/d/optout.

Reply via email to