Set types¶
A set is a constructed data type used to store an unordered collection of unique elements. Unlike lists, elements in a set are not indexed and are automatically deduplicated.
Sets are enclosed in curly braces ({}) with elements separated by commas (,). Whitespace surrounding the elements is ignored, allowing the use of newlines, tabs, and spaces for formatting purposes.
The set type must be declared using the SET<E> keyword, where E represents the data type of the elements. Elements can be any predefined data type or constructed data type other than records and paths.
Declaration example¶
'''
CREATE GRAPH TYPE IF NOT EXISTS set_type AS
{ NODE Person
( {
name STRING PRIMARY KEY,
email_list SET<STRING> DEFAULT SET{"eee@fff.com", "ggg@hhh.org"}
} )
}
'''
Supported operators¶
The set type supports the following operators:
| Operator | Name | Description | Example | Result |
|---|---|---|---|---|
|| |
Union | Merges two sets into a new set. Duplicate elements are automatically removed. | RETURN SET{1, 2} || SET{2, 3} |
{1, 2, 3} |
IN |
Inclusion | Checks if a specific element exists within the set. | RETURN 1 IN SET{1, 2, 3} |
true |
NOT IN |
Exclusion | Checks if a specific element does not exist within the set. | RETURN 4 NOT IN SET{1, 2, 3} |
true |