pepe wrote:
> SQL does not use the equality comparison for null values, it uses 'IS
> NULL' instead. Convenient, isn't it? ;)

Right, because NULL really means "unknown", and SQL uses 3-valued logic, 
so NULL == NULL actually returns NULL, not TRUE or FALSE -- that is, we 
don't know whether the two NULL values are "really" equal.  (Unlike in 
Ruby, where nil and false are both false in a logical context, SQL NULL 
is not FALSE.)

So, if I remember my SQL correctly:
NULL == TRUE yields FALSE
NULL == FALSE yields FALSE
NULL == NULL yields NULL
which is why it's necessary to have the special IS NULL syntax:
NULL IS NULL yields TRUE

> 
> Apparently Rails' magic does not go as far as to check if the NIL
> value is one of the values in the array to generate the correct SQL
> statement so I think you'll have to do it yourself and generate a
> string such as:
> 
> conditions = "org is null or org in ('ABC', 'XYZ')"

I think you're right.  I don't see another good way to do it.  I wonder, 
though, if COALESCE() would be useful in certain cases.

> 
> This should be so easy to implement that I am not sure why it has not
> already been done.

Interesting question.  I've never needed this except as part of complex 
queries where I'm already writing SQL anyway, but YMMV.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to