Subsections


Set Expressions

OQL allows us to perform the following operations on sets and bags: union, intersection, difference and inclusion. The operands can be sets or bags. For all these operators, when the operand's collection types are different (bag and set), the set is first converted to a bag and the result is a bag.

union Operator

The union operator performs the union of two sets or bags. This operator has the same precedence as the logical or operator.
General Information
Operator union
Syntax expr union expr
Type binary
Operand Types set or bag
Result Type set if both two operands are of type set, bag otherwise
Functions returns the union of the two operands.

Expression Examples
expression result
set(1, 2) union set(2, 3) set(1, 2, 3)
set(1, 2) union bag(2, 3) bag(1, 2, 2, 3)
list(1, 2) union bag(2, 3) raises an error

intersect Operator

The intersect operator performs the intersection of two sets or bags. This operator has the same precedence as the logical and operator.
General Information
Operator intersect
Syntax expr intersect expr
Type binary
Operand Types set or bag
Result Type set if both two operands are of type set, bag otherwise
Functions returns the intersection of the two operands.

Expression Examples
expression result
set(1, 2) intersect set(2, 3) set(2)
set(1, 2) intersect bag(2, 3) bag(2)
bag(1, 2, 2, 3) intersect bag(2, 3, 2) bag(2, 2, 3)
list(1, 2) intersect bag(2, 3) raises an error

except Operator

The except operator performs the difference between two sets or bags. This operator has the same precedence as the logical or operator.
General Information
Operator except
Syntax expr except expr
Type binary
Operand Types set or bag
Result Type set if both two operands are of type set, bag otherwise
Functions returns the difference of the two operands.

Expression Examples
expression result
set(1, 2) except set(2, 3) set(1)
set(1, 2) except bag(2, 3) bag(1)
set(1, 2, 10) except bag(12) bag(1, 2, 10)
list(1, 2) except bag(2, 3) raises an error

Inclusion Operators

The inclusion operators for sets and bags are the comparison operators less than/greater than introduced in a previous section.
General Information
Operator <
  <=
  >
  >=
Syntax expr < expr
  expr <= expr
  expr > expr
  expr >= expr
Type binary
Operand Types set or bag
Result Type boolean
Functions coll1 < coll2 : returns true if and only if coll1 is included in coll2 but not equal to coll2
  coll1 > coll2 : returns true if and only if coll2 is included in coll1 and not equal to coll1
  coll2 <= coll1 : returns true if and only if coll1 is included in coll2 or equal to coll2
  coll1 >= coll2 : returns true if and only if coll2 is included in coll1 or equal to coll1

Expression Examples
expression result
set(1, 2) < set(2, 3) false
set(1, 2) < set(2, 3, 1) true
set(1, 2) < bag(2, 3, 1) true
set(1, 2) <= bag(2, 1) false
set(1, 2) >= bag(2, 1) false

EyeDB manual