[Ur] Checking for equality in SQL expressions fails for None

Adam Chlipala adamc at csail.mit.edu
Tue Nov 19 08:01:40 EST 2013


On 11/18/2013 05:54 PM, Istvan Chung wrote:
> If a value of None is placed in column Bar of table foo, the SQL
> expression
>      SELECT * FROM foo WHERE foo.Bar={[None]}
> will fail to find any rows. This appears to be a consequence of the
> fact that in SQL, [NULL=NULL] is false, and the implementation detail
> that None is represented with NULL in databases. A workaround is to
> use [IS NULL] instead, but it seems to me that this should be fixed in
> Ur/Web.
>    

I wouldn't say it's an "implementation detail" that [None] maps to 
'NULL'; it's part of the semantics of the Ur/Web SQL interface.  For 
better or worse, this interface is designed to expose SQL and its 
semantics directly to the Ur/Web programmer.

For the particular code you wrote, I suggest going with [IS NULL] like 
you mentioned.  For more complex comparisons, consider the [eqNullable] 
and [eqNullable'] functions from the standard library, whose types 
you'll find in lib/ur/top.urs.



More information about the Ur mailing list