Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
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 )


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


Return type

  • collection


Venn diagram



Examples

ExpressionResultType
DIFFERENCE ( [ "a", "b", "c"] , [ "c", "d", "e" ] )[ "a" , "b" ]String (multivalued)
DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )[ "bv" ]String (multivalued)
DIFFERENCE ( 1 , 1 )[ ]Integer (multivalued)
DIFFERENCE( [ 1, 2 ], ? )?Integer (multivalued)

Back to top

Panel
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 )
Inputs
  • collection1, collection2 - Collections to be compared. These collections must be of the same base type.

Return type

  • collection

Venn diagram

Image Removed

Examples

ExpressionResultTypeSYMMETRIC_DIFFERENCE ( [ "a" , "b" , "c" ] , [ "c" , "d" , "e" ] )[ "a", "b", "d", "e" ]String (multivalued)SYMMETRIC_DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )[ "bv" ]String (multivalued)SYMMETRIC_DIFFERENCE ( 1 , 1 )[ ]Integer (multivalued)


Back to top

Now an example with the UNPACK function. We leave out the first instance from the previous example.

 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.

See also Collection function SYMMETRIC_DIFFERENCE

Panel
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.

Person instancePerson.NamePerson.Age
Person_1Kim24
Person_2Rick25
Person_3Bob25
ExpressionResultTypeNote
COLLECT Person.Age FROM ALL Person[ 24 , 25 ]String (multivalued)
SIZE ( COLLECT Person.Age FROM ALL Person )3IntegerThe intermediary collection is [ 24, 25, 25 ]

 TSL:

The ages present are: [[[ COLLECT Person.Age FROM ALL Person ]]].

The ages present are: 24, 25, 25.StringThe intermediary collection is [ 24, 25, 25 ]
SIZE ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )2IntegerThe duplicates in the intermediary collection are filtered by the UNIQUE function
Person instancePerson.NamePerson.Age
Person_2Rick25
Person_3Bob25
ExpressionResultTypeNote
COLLECT Person.Age FROM ALL Person[ 25 ]Integer (multivalued)UNPACK ( COLLECT Person.Age FROM ALL Person )ErrorThe collection contains 2 elements [ 25 , 25 ]UNPACK ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )25
UI Text Box
typenote
Back to top