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

Todd Roth toddjroth at gmail.com
Sun Jul 19 07:20:08 EDT 2015


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)






[1]
Some constructor unification variables are undetermined in declaration
(look for them as "<UNIF:...>")
Decl: 

.....
val rec
 exampleQ :
  {} ->
   transaction
    (list
      $(([]) ++
         map (fn fields :: {Type} => $fields)
          ([Table1 =
             (fn fields :: ({Type} * {Type}) => fields.1)
              (([Table2Val = (option int, <UNIF:U47::Type>).1]) ++ [Id = int], 
                []), 
             Table2 =
              (fn fields :: ({Type} * {Type}) => fields.1)
               ((map (fn p :: (Type * Type) => p.2)
                  <UNIF:U242::{(Type * Type)}>) ++
                 [Id =
                   (fn p :: (Type * Type) => p.2)
                    (option int, <UNIF:U47::Type>)], [])]))) =
  fn $x : {} =>
   case $x of
    {} =>
     queryL
      [[Table1 =
         (fn fields :: ({Type} * {Type}) => fields.1)
          (([Table2Val = (option int, <UNIF:U47::Type>).1]) ++ [Id = int], []), 
         Table2 =
          (fn fields :: ({Type} * {Type}) => fields.1)
           ((map (fn p :: (Type * Type) => p.2) <UNIF:U242::{(Type * Type)}>)
             ++
             [Id =
               (fn p :: (Type * Type) => p.2) (option int, <UNIF:U47::Type>)], 
             [])]] [[]]
      (Basis.sql_query [[]] [[]]
        [[Table1 =
           ([Table2Val = (option int, <UNIF:U47::Type>).1]) ++ [Id = int], 
           Table2 =
            map (fn p :: (Type * Type) => p.2)
             (<UNIF:U242::{(Type * Type)}> ++
               [Id = (option int, <UNIF:U47::Type>)])]]
        [[Table1 =
           (fn fields :: ({Type} * {Type}) => fields.1)
            (([Table2Val = (option int, <UNIF:U47::Type>).1]) ++ [Id = int], []),
                                                                                 
           Table2 =
            (fn fields :: ({Type} * {Type}) => fields.1)
             ((map (fn p :: (Type * Type) => p.2) <UNIF:U242::{(Type * Type)}>)
               ++
               [Id =
                 (fn p :: (Type * Type) => p.2) (option int, <UNIF:U47::Type>)],
                                                                                
               [])]] [[]]
        {Rows =
          Basis.sql_query1 [[]] [[]]
           [[Table1 =
              ([Table2Val = (option int, <UNIF:U47::Type>).1]) ++ [Id = int], 
              Table2 =
               map (fn p :: (




More information about the Ur mailing list