[Ur] checking for equality between optional and non-optional values in queries

Todd Roth toddjroth at gmail.com
Sun Jul 19 14:07:16 EDT 2015


Thank you!  The SQL function was the missing piece.  I had tried sql_nullable without the SQL call but was getting an “Unbound structure” error.


> On Jul 19, 2015, at 9:40 AM, Adam Chlipala <adamc at csail.mit.edu> wrote:
> 
> On 07/19/2015 07:20 AM, Todd Roth wrote:
>> Another newbie question… How do you check for equality between optional and non-optional columns in different tables when doing join queries?  The following exampleQ query does not compile.  I get the errors shown in [1]
>> 
>> 
>> table table2 : { Id : int, SomeVal : string}
>> 	       PRIMARY KEY Id
>> 
>> table table1 : { Id : int, Table2Val : option int }
>> 	       PRIMARY KEY Id,
>> 	       CONSTRAINT Table2Val FOREIGN KEY Table2Val REFERENCES table2(Id)
>> 	
>> fun exampleQ () = queryL (SELECT * FROM table1 LEFT JOIN table2 ON table1.Table2Val = table2.Id)
> 
> Here's the simple fix:
> 
> fun exampleQ () = queryL (SELECT * FROM table1 LEFT JOIN table2
>                                     ON table1.Table2Val = {sql_nullable (SQL table2.Id)})
> 
> 
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur




More information about the Ur mailing list