Page History
Learn more about the collection functions EXISTS, EACH, ALL, COLLECT FROM WHERE, COLLECT FROM NAMED WHERE, COLLECT, UNPACK, LIST, SIZE, UNIQUE, SUBSET OF, UNION, INTERSECTION, DIFFERENCE, SYMMETRIC_DIFFERENCE.
Overview
Function | Description |
---|---|
EXISTS | Determines |
...
Table of Contents | ||
---|---|---|
|
...
bgColor | white |
---|
EXISTS
...
whether an instance of a specified entity exists, optionally meeting certain criteria. |
...
Syntax
...
...
EXISTS instances [ WHERE ( condition ) ]
- instances - Instances to search.
- condition - boolean expression that represents the criterion the instance has to meet.
Return type
- boolean
Examples
Suppose the following data model.
...
EACH | Determines |
UI Text Box | ||
---|---|---|
| ||
Please note that you can use a COLLECT expression as well for collecting instances for which the EXISTS should hold. E.g., EXISTS (COLLECT Person FROM ALL Person WHERE (Person.gender = "f")) WHERE ( Person.age < 25 ). In case that the list of instances for which the EXISTS should hold is an EMPTY list, then the EXISTS expression returns FALSE. |
...
bgColor | white |
---|
EACH
...
whether all instances of a specified entity meet a certain criteria |
...
Syntax
Code Block |
---|
EACH instances WHERE ( condition ) |
- instances - A collection of instances to search.
- condition - Boolean expression that represents the criterion the instance has to meet.
Return type
- boolean
Examples
Suppose the following data model.
...
. |
...
...
...
type | note |
---|
...
...
In case that the list of instances for which the EACH should hold is an EMPTY list, then the EACH expression returns TRUE.
Creates |
...
bgColor | white |
---|
ALL
...
a collection of all instances of a specified |
...
Syntax
Code Block |
---|
ALL entity |
- entity - Entity of which to collect all its instances.
Return type
- collection of entity instances
Examples
...
entity. |
...
...
bgColor | white |
---|
...
Creates a collection of entity or attribute instances (meeting certain criteria |
...
Syntax
Code Block |
---|
COLLECT entity | attribute FROM collection [ WHERE ( expression ) ] |
- entity or attribute - Entity or attribute to collect.
- collection - A collection of entity instances.
- expression - Boolean expression that represents the criterion the instance has to meet.
Return type
- collection of entity instances
- collection of attribute values
UI Text Box | ||
---|---|---|
| ||
A collections contains no duplicates. Intermediary |
Examples
Suppose the following model. Entity Teacher
has a multivalued relation with entity Child
via the relation Teacher.teaches_Children
.
...
) |
...
COLLECT Child.name FROM ALL Child
WHERE ( Child.hobbies = "Reading" )
...
. |
...
...
Version of |
...
COLLECT FROM [WHERE] |
...
for complex nested selections |
...
Syntax
Code Block |
---|
COLLECT entity | attribute FROM collection NAMED alias [ WHERE ( expression ) ] |
- entity or attribute - Entity or attribute to collect. This should contain the alias, e.g. alias.Name.
- collection - A collection of entity instances.
- alias - A name for the collection.
- expression - Boolean expression that represents the criterion the instance has to meet.
Return type
- collection of entity instances
- collection of attribute values
UI Text Box | ||
---|---|---|
| ||
A collections contains no duplicates. Intermediary |
Examples
Suppose the following model with only instances of entity Person
. Person.hasChildren
is a relation from Person to Person.
...
To retrieve all the parent names, we use this expression:
Code Block |
---|
COLLECT Parent.name
FROM
COLLECT Person
FROM ALL Person
WHERE ( Person.hasChildren != ? ) NAMED Parent |
This expression results in “Rick”, “Julia” and “Joan”.
To retrieve all children names, we use this expression:
Code Block |
---|
COLLECT Child
FROM (
COLLECT Person.hasChildren
FROM ALL Person
WHERE ( Person.hasChildren != ? ) ) NAMED Child |
This expression results in a collection of three instances of Person
(i.e Person_1
, Person_3
and Person_5
, with names Kim, Bob and Sam).
To retrieve all children younger than 15, we use this expression:
Code Block |
---|
COLLECT Child
FROM (
COLLECT Person.hasChildren
FROM ALL Person
WHERE ( Person.hasChildren != ? ) ) NAMED Child
WHERE ( Child.Age < 15 ) |
This expression results in a collection of two instances of Person
(i.e Person_3
and Person_5
, with names Bob and Sam).
To retrieve the children’s names with a parent older than 40 years:
Code Block |
---|
COLLECT Child.Name
FROM (
COLLECT Person.hasChildren
FROM ALL Person
WHERE ( Person.hasChildren != ? AND Person.Age > 40 ) ) NAMED Child |
This expression results in a collection with only the name “Kim”.
You can make it as complex as you like, for example:
Code Block |
---|
COLLECT Child.Name
FROM (
COLLECT Parent.hasChildren
FROM (
COLLECT Person
FROM ALL Person
WHERE ( Person.hasChildren != ? ) ) NAMED Parent
WHERE ( Parent.Age > 40 )
) NAMED Child
WHERE ( Child.Age < 18 ) |
...
with |
...
type | note |
---|
...
an alias |
...
. |
...
Code Block |
---|
thisPerson := Person ;
COLLECT Person
FROM ALL Person
WHERE ( Person != thisPerson ) |
...
...
bgColor | white |
---|
...
Extracts the value from a single valued collection or list. |
...
Is the inverse of the LIST |
...
Syntax
Code Block |
---|
UNPACK ( collection/list ) |
- collection/list - A collection or list of one entity or attribute instance.
Return type
- entity instance
- attribute value of any type
Examples
Suppose the following data model.
...
UNPACK ( COLLECT Person.name FROM ALL Person WHERE ( Person.SequenceNumber = MIN ( COLLECT Person.SequenceNumber FROM ALL Person ) ) )
= “Ron”
...
function |
...
. |
...
UNPACK ( COLLECT Person.name FROM ALL Person WHERE ( Person.SequenceNumber = MAX ( COLLECT Person.SequenceNumber FROM ALL Person ) ) )
= “Jenny”
...
...
bgColor | white |
---|
LIST
...
LIST | Creates a list based on a value. |
...
Is the inverse of the UNPACK function |
...
Syntax
Code Block |
---|
LIST ( attribute/collection ) |
- attribute - An attribute of any data type.
- collection/list - A collection or list of values.
Return type
- a multivalued list with entries of any type
Examples
...
. |
...
...
LIST ( COLLECT Person.name FROM ALL Person ) = [ "Bob" , "Jane" , "Mary" , "Rick" , "Ron" , "Jenny" ]
- In this example the
LIST
function adds no value, as the result of theCOLLECT
is already a list.
- In this example the
LIST ( COLLECT Person.SequenceNumber FROM ALL Person ) = []
- As Jenny has an unknown sequence number, the result of the
COLLECT
expression is?
. TheLIST
function creates an empty list in case the parameter has?
value.
- As Jenny has an unknown sequence number, the result of the
...
bgColor | white |
---|
...
This function determines the size of a collection.
Syntax
Code Block |
---|
SIZE ( collection ) |
- collection - A collection of attribute or entity instances. This can be an expression or a relation attribute for instance.
Return type
- integer
Example
Suppose you have a Parent
and a Child
entity, where Parent
has a multivalued relation with Child
via the relation Parent.has_Children
. With this model the following instances are created:
...
Then:
...
UI Text Box | ||
---|---|---|
| ||
SIZE and COUNT are similar except for ?: SIZE ( ? ) results in 0, while COUNT ( ? ) results in ? |
...
bgColor | white |
---|
UNIQUE
The UNIQUE
function filters duplicate items from a collection. An expression resulting in a collection, never contains duplicate values. A subexpression with the COLLECT
statement however, can contain duplicates. See the note on collections and duplicates for more info.
Syntax
Code Block |
---|
UNIQUE ( collection ) |
- collection - A collection of attribute or entity instances.
Examples
Suppose the following model.
...
bgColor | white |
---|
...
SIZE | Determines the size of a collection. |
UNIQUE | Filters duplicate items from a collection resulting from a subexpression in a larger expression. |
SUBSET OF | Returns |
TRUE if the items in a collection are all present in another |
...
Syntax
Code Block |
---|
collection1 SUBSET OF collection2 |
- collection1 - The collection that is tested to be a subset of the second collection.
- collection2 - The collection that is tested to hold all the items in the first collection.
Return type
- boolean
Diagram
Examples
...
1 SUBSET OF Address.Numbers
Given Adress.Numbers = ?
...
type | note |
---|
...
collection |
...
. |
...
...
bgColor | white |
---|
UNION | Adds two collections of the same base type to a |
...
Syntax
Code Block |
---|
UNION ( collection1 , collection2 ) |
...
...
new |
...
Return type
collection |
...
Diagram
Examples
Suppose you have a Parent
and a Child
entity, where Parent
has a multivalued relation with Child
via the relation Parent.has_Children
. With this model the following instances are created:
...
. |
...
...
bgColor | white |
---|
INTERSECTION
...
INTERSECTION | Determines the intersection of two |
...
collections. |
...
Syntax
Code Block |
---|
INTERSECTION ( collection1 , collection2 ) |
...
...
Return type
- collection
Diagram
Examples
Suppose the following model. Entity Teacher
has a multivalued relation with entity Child
via the relation Teacher.teaches_Children
.
...
DIFFERENCE | Determines the difference between 2 collections. Returns |
...
bgColor | white |
---|
DIFFERENCE
...
a collection containing all the items from collection1 that are not present in collection2. |
...
Syntax
Code Block |
---|
DIFFERENCE ( collection1 , collection2 ) |
...
...
Return type
- collection
Diagram
Examples
...
...
bgColor | white |
---|
...
Determines the symmetric difference between two collections. |
...
Returns a collection with the elements of the provided collections which are in either one of the collections, but not in both |
...
Syntax
Code Block |
---|
SYMMETRIC_DIFFERENCE ( collection1 , collection2 ) |
...
. |
...
Return type
- collection
Diagram
Examples
...
...
A note on collections and duplicates
...
An expression resulting in a collection does not contain duplicates. Please be aware however, that intermediary results of a COLLECT
statement can contain duplicates. You have to be aware of this when using the SIZE
or UNPACK
function, or when using TSL.
This is best illustrated with the following examples.
...
TSL:
The ages present are: [[[ COLLECT Person.Age FROM ALL Person ]]].
...
Now an example with the UNPACK function. We leave out the first instance from the previous example.
...
Functions
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
...
UI Text Box | ||
---|---|---|
| ||
Only the intermediary results of a |
...