On Sep 10, 2010, at 11:47 AM, Jon Nelson wrote:

> I found something interesting recently: I have a table with a boolean column.
> When I wrote (low-level) sqlalchemy code, I used constructs like this:
> 
> query = query.where(table.c.boolean_column==True)
> 
> and when executed the query uses '='.
> 
> In the psql console, however, I had been using 'boolean_column IS
> true', and my indexes are partial indexes which specify the same
> (using IS not equals).
> 
> When I use ==None  then I get 'IS NULL'.
> 
> I'm not sure which is the totally *right* way to do this, but there is
> a difference. If I wanted to get IS true (or IS false) out of
> sqlalchemy, how would I do it?

IS is important for NULL, since nothing can be "equals" to NULL in relational 
DBs.   NULL = NULL returns false.

"IS true" and "IS false" is not so critical, however, unless you need to 
compare NULL columns to "false" and expect to get a "true" value for that 
(which I would not recommend; I'd test for IS NULL before comparing to anything 
else).     It could be changed by overriding the compilation for 
_BinaryExpression but I don't think its necessary.   



> 
> 
> -- 
> Jon
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

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

Reply via email to