[Ur] SQL Count

David Snider david at davidsnider.net
Tue Mar 2 21:10:08 EST 2010


Ah, Thanks.

As you may have noticed I lifted it out of your Bison Lisp slides, I 
didn't realize it was Pseudo-code.

On 3/2/2010 09:05 PM, Adam Chlipala wrote:
> David Snider wrote:
>> fun isValid r =
>>     oneRow (SELECT COUNT(*) FROM users
>>                 WHERE Username = {[r.Username]}
>>                   AND Password = {[r.Password]}) = 1
>>
>> It seems to be treating COUNT(*) as a comment. How do I get a record 
>> count?
>
> Just include spaces before and after the asterisk.  There are also a 
> few other problems here:
>
> - You'll need to include an [AS] name for the expression column you're 
> creating.  Every [SELECT]ed column that isn't a projection of a column 
> from a table must have an [AS] name in Ur/Web.
> - [oneRow] will never return an integer.  You probably want [oneRowE1].
> - The result of a query can never be used as a direct operand to the 
> equality operator.  This is because query operations must live inside 
> the [transaction] monad.  If you're not familiar with the basic 
> techniques of monadic programming, I'd recommend finding a tutorial on 
> monads in Haskell.
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur




More information about the Ur mailing list