LIST and ARRAY
Kùzu supports two list-like data types: (i) variable-length lists, simply called LIST
, and (ii)
fixed-length lists, called ARRAY
.
LIST
A LIST
can contain an arbitrary number of values, but they must all be of the same type. The types
inside a LIST
can be any of those supported by Kùzu, including nested/complex types. Some examples are shown below:
STRING[]
is aLIST
ofSTRING
valuesINT64[]
is aLIST
ofINT64
valuesSTRING[][]
is aLIST
ofLIST
ofSTRING
valuesMAP(STRING, STRING)[]
is aLIST
ofMAP(STRING, STRING)
values
Create a LIST
In Cypher, enclosing comma-separated values in square brackets will store the values as a LIST
. The type
of the elements is inferred by the query parser during the binding stage.
Output:
You can also create a LIST
by explicitly calling the creation function as follows.
Output:
UNWIND
a LIST
Output:
ARRAY
ARRAY
is a special case of LIST
, in which the number of elements is fixed. Just like a LIST
,
all values in ARRAY
must be of the same type. The number of elements is specified as an
integer inside square brackets. Some examples are shown below:
INT64[256]
is anARRAY
ofINT64
values, with 256 elementsDOUBLE[512]
is anARRAY
ofDOUBLE
values, with 512 elements
An ARRAY
is useful for storing items like embeddings (for use in similarity search or in machine learning
via our PyTorch Geometric integration), where the number of elements is fixed and known in advance.
You can create an array of any data type and size, including nested types using explicit casting. Some examples are listed below:
ARRAY
of type INT64
and size 4
This is an example of creating an array with elements that are primitive types (integers).
Output:
ARRAY
of LIST
s of type INT64
and size 3
This is an example of creating an array whose elements are nested types that are themselves LIST
s
containing elements of a primitive type (integers).
Output:
UNWIND
an ARRAY
UNWIND
ing an ARRAY
works exactly as shown above for the LIST
type.
Output: