next up previous contents
Next: Syntactic Extensions and Up: Select Queries Previous: Select Expressions and

Conditions

 

Conditions in the OPM Query Language are used to restrict the possible instantiations of variables in a SELECT, DELETE or UPDATE query. Conditions are formed using conjunctions and disjunctions of various atomic comparisons of expressions.

<conditions> ::= <atomic condition>
               | ( <conditions> )
               | <conditions> AND <conditions>
               | <conditions> OR <conditions>
               ;
<atomic condition> ::= <expression> <is null op>
                     | <expression> <bin op> <expression>
                     | <expression> <comp op> ALL <variable>
                     | <expression> <match op> <string>
                     ;
<is null op> ::= IS NULL
               | IS NOT NULL
               ;
<bin op> ::= <comp op>
           | <in op>
           | <contains op>
           ;
<comp op> ::= '='  | '!='  | '>' | '>='  | '<'  | '<=' 
            ;
<contains op> ::= CONTAINS | NOT CONTAINS
                ;
<in op> ::= IN | NOT IN
          ;
<match op> ::= MATCH | NOT MATCH
             ;

An atomic condition is said to be satisfied by a particular instantiation of variables if, for that instantiation of variables, the values of the expressions involved in the condition make the condition true. More precisely:

  1. A condition e IS NULL is satisfied iff the value of the expression e in the variable instantiation is , while e IS NOT NULL is satisfied if the value of e is not equal to Null ;

  2. A condition , where is one of =, !=, <, >, <= or >=, is satisfied if the values associated with and are both not equal to Null , and the binary relationship associated with holds between and . (e.g., = is satisfied if the values of and are equal and not equal to Null , while != is satisfied if the values associated with and are not equal, and neither value is equal to Null .)

  3. A condition e ALL v, where e is an expression and v a variable, is satisfied by a particular instantiation iff for any valid variable instantiation which is equal to the current instantiation on all variables other than v (and possibly on v as well), the condition is satisfied;

  4. A condition CONTAINS is satisfied iff the value of is a set and the value of occurs in . NOT CONTAINS is satisfied if the value of is a set, the value of is not equal to Null , and the value of does not occur in the value of ;

  5. A condition IN is satisfied iff the value of is a set and the value of occurs in . NOT IN is satisfied if the value of is a set, the value of is not equal to Null , and the value of does not occur in the value of ;

  6. A condition MATCH is satisfied if the values of and are strings, and the value of , treated as a regular expression matches the value of . NOT MATCH is satisfied if the values of and are strings, and the value of does not match the value of .
and so on.

For example suppose we have a variable instantiation which is valid for the FROM statement

       FROM X IN PERSON, Y IN X.owns[FRAGMENT]
Then the condition Y IS NULL would be satisfied iff the owns attribute of X is the empty set.

Note: this semantics of comparison operators with respect to Nulls appears to be reasonable and necessary because of the use of Null to represent empty set-valued attributes. For example, if we wished to ask a query ``what are the names of people who own a Fragment owned by John'', we could write

     SELECT X.name
     FROM   X IN PERSON, J IN PERSON, 
            XF IN X.owns[FRAGMENT], JF IN J.owns[FRAGMENT]
     WHERE  J.name = "John"
     AND    XF = JF
     ;
If we made the condition XF = JF true when both XF and JF were equal to Null , and if the owns attribute of John was the empty set, then this query would return the names of any People that do not own any Fragments.



next up previous contents
Next: Syntactic Extensions and Up: Select Queries Previous: Select Expressions and