Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-11-03 Thread Ladislav Lenart
Hello. On 31.10.2014 18:33, Simon King wrote: 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*

Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-11-03 Thread Simon King
On 3 Nov 2014, at 13:08, Ladislav Lenart lenart...@volny.cz wrote: Hello. On 31.10.2014 18:33, Simon King wrote: 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

[sqlalchemy] [Q] Semantic difference in not equal operator

2014-10-31 Thread Ladislav Lenart
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

Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-10-31 Thread Simon King
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

Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-10-31 Thread Jonathan Vanasco
I agree with what Simon said, and want to point out that he is assuming that that Foo.bar is a relationship of Foo to Bar based on Foo.bar_id = Bar.id But you should understand that these are two completely different queries AND you haven't described your model at all.