Set constructor

EQL allows users to write sets directly in queries.

The syntax of the set constructor is:
{<expr1> [,<expr2>]*}
where the curly braces enclose a comma-separated list of one or more expressions.
For example, this is an integer set:
{ 1, 4, 7, 10 }
while this is a string set:
{ 'Red', 'White', 'Merlot', 'Chardonnay' }
Keep the following in mind when using set constructors:
  • Set constructors may appear anywhere in a query where an expression is legal. (Because set constructors have a set type, you will get an EQL checking error if you use a set constructor in a context that expects an atomic value.)
  • The individual elements of the set constructor may be arbitrary expressions, as long as they have the correct type. For instance, you may write the following as long as x, y, and z are integers:
    { x, y + z, 3, HIERARCHY_LEVEL(managedAttr) }
  • All of the expressions within the curly braces must have the same type. For example, you cannot mix integers and strings.
  • Empty set constructors are not allowed; there must be at least one expression within the curly braces.

Note that EQL does not auto-convert integers to doubles or string literals to managed-attribute values within a set constructor. Therefore, writing {1, 2.5} results in a type error. In this case, you can use TO_DOUBLE or TO_MANAGED_VALUE to perform the conversion manually (for example, {TO_DOUBLE(1), 2.5}).

Set constructor examples

In this first example, the SELECT clause constructs a string-type set (named selectWines) that contains 'Red' and 'White' as its two elements. The selectWines set is then used in a HAVING clause to limit the returned records to those have WineType assignments of either 'Red' or 'White'.
RETURN results AS
SELECT
   {'Red', 'White'} AS selectWines,
   WineID AS idRec,
   WineType AS wines,
   Body AS bodyAttr
HAVING wines IN selectWines
ORDER BY idRec
This second example is similar to the first example, except that the set is used in a WHERE clause:
RETURN results AS
SELECT
   WineID AS idRec,
   WineType AS wines,
   Body AS bodyAttr
WHERE WineType IN {'Red', 'White'} 
ORDER BY idRec

Both queries would return only records with a WineType of 'Red' or 'White'.