Array Type
The array data type provides the capability to store a list of primitive data type values in a single column. All arrays in Kinetica are one-dimensional and 1-based. They are also unbounded, though the number of items in the array can be specified upon table/column creation for compatibility with other databases. Arrays can be lists of any of the following data types:booleanintlongulongfloatdoublestring
Create Table
Insert Data
Retrieve Data
To retrieve the 2nd item of an integer array and the entirety of a string array:Array Functions
Scalar Functions
ARRAY_APPEND(array, value)
ARRAY_APPEND(array, value)
array with value appended to the end.ARRAY_CONCAT(arr1, arr2)
ARRAY_CONCAT(arr1, arr2)
arr1 followed by all of
the elements of array arr2.ARRAY_CONTAINS(array, value)
ARRAY_CONTAINS(array, value)
value is present in array.ARRAY_CONTAINS_ALL(arr1, arr2)
ARRAY_CONTAINS_ALL(arr1, arr2)
arr2 is present in array arr1; otherwise
returns false.ARRAY_CONTAINS_ANY(arr1, arr2)
ARRAY_CONTAINS_ANY(arr1, arr2)
arr2 is present in array arr; otherwise
returns false.ARRAY_DISTINCT(array)
ARRAY_DISTINCT(array)
array values with duplicates removed.ARRAY_EMPTY(array)
ARRAY_EMPTY(array)
array is empty; otherwise returns false.ARRAY_EXCEPT(arr1, arr2)
ARRAY_EXCEPT(arr1, arr2)
arr1 with the ones that
also appear in array arr2 removed.ARRAY_INTERSECT(arr1, arr2)
ARRAY_INTERSECT(arr1, arr2)
arr1 that also appear
in array arr2.ARRAY_ITEM(array, pos)
ARRAY_ITEM(array, pos)
array at the given 1-based pos position.See examples.ARRAY_LENGTH(array)
ARRAY_LENGTH(array)
array at the 1st dimension.See examples.ARRAY_LOWER(array, dim)
ARRAY_LOWER(array, dim)
array in the given dim dimension; since all arrays
are 1-dimensional, only specifying a dimension of 1 will return a value, and since
array indices are 1-based, that value will always be 1.ARRAY_NDIMS(array)
ARRAY_NDIMS(array)
array; since all arrays are
1-dimensional, that number will always be 1.ARRAY_NOT_EMPTY(array)
ARRAY_NOT_EMPTY(array)
array is not empty; otherwise returns false.ARRAY_SLICE(array, from, to)
ARRAY_SLICE(array, from, to)
array between the from index
(inclusive) up to the to index (exclusive) using 0-based indexing. Negative indexes
are treated as offsets from the end of the array.ARRAY_TO_STRING(array, delim)
ARRAY_TO_STRING(array, delim)
array into a string delimited by delim.See examples.ARRAY_UPPER(array, dim)
ARRAY_UPPER(array, dim)
array in the given dim dimension; since all arrays
are 1-dimensional, only specifying a dimension of 1 will return a value, and since
array indices are 1-based, that value will always be equivalent to ARRAY_LENGTH.MAKE_ARRAY(value)
MAKE_ARRAY(value)
value element.STRING_TO_ARRAY(str, delim)
STRING_TO_ARRAY(str, delim)
str, delimited by delim, into an array.See examples.Examples
ARRAY_ITEM
ARRAY_LENGTH
ARRAY_TO_STRING
STRING_TO_ARRAY
Aggregation/Transposition Functions
These functions can be used to convert primitive column values into arrays of those values (aggregation) or to convert array columns into columns of primitive values (unnest).ARRAY_AGG(expr)
ARRAY_AGG(expr)
ARRAY_AGG_DISTINCT(expr)
ARRAY_AGG_DISTINCT(expr)
UNNEST_JSON_ARRAY
UNNEST_JSON_ARRAY
Examples
ARRAY_AGG
ARRAY_AGG_DISTINCT
UNNEST_JSON_ARRAY
TheUNNEST_JSON_ARRAY function transposes array values into columnar data.
The two forms of the UNNEST_JSON_ARRAY function follow, one for cases where
only one column needs to be unnested and one for cases where more than one
column needs to be unnested. See
examples.
<column alias>
<column alias>
* to select the column.<table name>
<table name>
<column name>
<column name>
WITH ORDINALITY
WITH ORDINALITY
ordinality.<column alias list>
<column alias list>
<table/columns aliases>.<ordinality alias>
<ordinality alias>
<table/columns aliases>,
if WITH ORDINALITY is specified.<table name>
<table name>
<table alias>
<table alias>
<column list>
<column list>
<table/columns aliases>
<table/columns aliases>
uai & uav,
respectively, and the corresponding ordinality index as index, all within the
virtual table unn use:WITH ORDINALITY
WITH ORDINALITY
<table/columns aliases>.Examples
The following examples use this data set as a baseline:av array in the example.arr_unn table into a
column of values aliased as uav:
ai array in the example.arr_unn table into a
column of values aliased as uai and the corresponding index in the original
array for each as a column of indices named ordinality:
ai & av arrays in the
example.arr_unn table into two columns of values aliased as uai &
uav in a virtual table with alias t, respectively:
ai & av arrays in the
example.arr_unn table into two columns of values aliased as uai &
uav in a virtual table with alias t, respectively, and adding the
corresponding index in the original array for each as a column of indices
aliased as index:
ai array in the example.arr_unn table into a
column of values aliased as uai, removing any duplicates across all arrays: