SUBSET function

The SUBSET row function takes two sets of the same data type and returns a Boolean true if (and only if) the second set is a subset of the first set.

The syntax of the SUBSET function is:
SUBSET(<set1>, <set2>)
where:
  • set1 is a set of any set data type (such as mdex:string-set). For example, set1 can be a multi-assign string attribute.
  • set2 is a set of the same set data type as set1. For example, if set1 is a multi-assign string attribute, then set2 must also be a set of strings (such as another multi-assign string attribute). set2 will be checked to see if it is completely contained within set1.
For example, assuming this statement:
SUBSET(A, B)
then the SUBSET result is true if (and only if) B is a subset of A.
Other examples of some results are as follows ({ } indicates an empty set):
SUBSET({ }, { }) = TRUE
SUBSET({ 1, 2, 3 }, { }) = TRUE
SUBSET({ 1, 2 }, { 1, 2 }) = TRUE
SUBSET({ 1, 2, 3 }, { 1, 2 }) = TRUE
SUBSET({ 1, 3, 5 }, { 1, 2 }) = FALSE
SUBSET({ 1, 2 }, { 'x', 'y', 'z' }) yields a checking error because the two sets are not of the same data type

Note that the empty set is always a subset of every other set (including the empty set).

SUBSET example

In this example, both Flavors and Body are multi-assign string attributes, and WineID is the primary key of the records:
RETURN results AS
SELECT 
   WineID AS id,
   SUBSET(Body, Flavors) AS subAttrs
FROM WineState
WHERE WineID < 5
ORDER BY id
The result of this statement might be:
id   subAttrs
-------------
| 1 | true  |
| 2 | true  |
| 3 | false |
| 4 | false |
-------------

The results show that the Flavors set is a subset of the Body set in Records 1 and 2, but not in Records 3 and 4.