Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
bgColorwhite

INTERSECTION


This function determines the intersection of two collections. It returns a collection containing the items that are present in both specified collections.


Syntax

Code Block
INTERSECTION ( collection1 , collection2 )



Inputs
  • collection1, collection2 - Collections to be intersected. These collections must be of the same base type.


Return type

  • collection


Venn diagram



Examples

Suppose the following model. Entity Teacher has a multivalued relation with entity Child via the relation Teacher.teaches_Children.


Teacher instanceChild instanceChild.nameChild.hobbies
Teacher_1Child_1“Kim”“Reading”, “Dancing”
Teacher_1Child_2“Rick”“Tennis”, “Dancing”
Teacher_1Child_3“Bob”“Painting”, “Basketball”, “Reading”
Teacher_2Child_1“Kim”“Reading”, “Dancing”
Teacher_2Child_3“Bob”“Painting”, “Basketball”, “Reading”
Teacher_2Child_4“Mary”“Football”
ExpressionResultType
INTERSECTION ( Teacher[Teacher_1].teaches_Children , Teacher[Teacher_2].teaches_Children )[ Child_1 , Child_3 ]Collection of Child instances
INTERSECTION ( Teacher[Teacher_1].teaches_Children.name , Teacher[Teacher_2].teaches_Children.name )[ "Kim" , "Bob" ]String (multivalued)
INTERSECTION ( Child[Child_1].hobbies , Child[Child_3].hobbies )[ "Reading" ]String (multivalued)
INTERSECTION ( Child[Child_2].hobbies , Child[Child_3].hobbies )[ ]String (multivalued)
INTERSECTION( ?, [ 1, 2 ] )UNKNOWNInteger (multivalued)


Back to top

...

bgColorwhite

DIFFERENCE

This function returns a collection containing all the items from collection1 that are not present in collection2.

Syntax

Code Block
DIFFERENCE ( collection1 , collection2 )

...

  • collection1, collection2 - Collections to be compared. These collections must be of the same base type.

Return type

  • collection

Venn diagram

Image Removed

Examples

...

Back to top

...

bgColorwhite

SYMMETRIC_DIFFERENCE

This function determines the symmetric difference between two collections. It 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 )

...

  • collection1, collection2 - Collections to be compared. These collections must be of the same base type.

Return type

  • collection

Venn diagram

Image Removed

Examples

...

Back to top

...

bgColorwhite

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.

...

UI Text Box
typenote

 Only the intermediary results of a COLLECT statement can contain duplicates. The functions UNIQUE, UNION, INTERSECTION, DIFFERENCE and SYMMETRIC_DIFFERENCE always return collections without duplicates.

Back to top