跳到主要内容

Array Functions

This page provides a comprehensive overview of Array functions in Databend, organized by functionality for easy reference.

Array Creation and Manipulation

FunctionDescriptionExample
ARRAY_APPENDAppends an element to the end of an arrayARRAY_APPEND([1, 2], 3)[1,2,3]
ARRAY_CONCATConcatenates two arraysARRAY_CONCAT([1, 2], [3, 4])[1,2,3,4]
ARRAY_PREPENDPrepends an element to the beginning of an arrayARRAY_PREPEND(0, [1, 2])[0,1,2]
ARRAY_DISTINCTRemoves duplicate elements from an arrayARRAY_DISTINCT([1, 1, 2, 2])[1,2]
ARRAY_FLATTENFlattens nested arrays into a single arrayARRAY_FLATTEN([[1, 2], [3, 4]])[1,2,3,4]
ARRAY_REMOVE_FIRSTRemoves the first element from an arrayARRAY_REMOVE_FIRST([1, 2, 3])[2,3]
ARRAY_REMOVE_LASTRemoves the last element from an arrayARRAY_REMOVE_LAST([1, 2, 3])[1,2]
ARRAY_SORTSorts elements in an arrayARRAY_SORT([3, 1, 2])[1,2,3]
ARRAY_UNIQUERemoves duplicate elements from an arrayARRAY_UNIQUE([1, 1, 2, 2])[1,2]
ARRAYS_ZIPCombines multiple arrays into an array of tuplesARRAYS_ZIP([1, 2], ['a', 'b'])[(1,'a'),(2,'b')]
RANGECreates an array of integers in the specified rangeRANGE(1, 5)[1,2,3,4]

Array Access and Information

FunctionDescriptionExample
ARRAY_GET / GETGets an element at the specified positionARRAY_GET([1, 2, 3], 1)2
ARRAY_LENGTH / ARRAY_SIZEReturns the number of elements in an arrayARRAY_LENGTH([1, 2, 3])3
ARRAY_INDEXOFReturns the position of the first occurrence of an elementARRAY_INDEXOF([1, 2, 3], 2)1
ARRAY_CONTAINS / CONTAINSChecks if an array contains a specific elementCONTAINS([1, 2, 3], 2)true
SLICE / ARRAY_SLICEExtracts a subarraySLICE([1, 2, 3, 4], 1, 2)[2,3]

Array Transformation

FunctionDescriptionExample
ARRAY_TRANSFORMApplies a lambda function to each elementARRAY_TRANSFORM([1, 2, 3], x -> x * 2)[2,4,6]
ARRAY_FILTERFilters elements based on a lambda conditionARRAY_FILTER([1, 2, 3], x -> x > 1)[2,3]
ARRAY_REDUCEReduces array to a single value using a lambda functionARRAY_REDUCE([1, 2, 3], 0, (s, x) -> s + x)6
ARRAY_APPLYApplies a function to each elementARRAY_APPLY([1, 2, 3], x -> x * x)[1,4,9]
ARRAY_AGGREGATEApplies an aggregate function to array elementsARRAY_AGGREGATE([1, 2, 3], 'sum')6
ARRAY_TO_STRINGConverts an array to a string with a delimiterARRAY_TO_STRING([1, 2, 3], ',')'1,2,3'
UNNESTExpands an array into a set of rowsSELECT UNNEST([1, 2, 3])1, 2, 3 (as rows)
开始使用 Databend Cloud
低成本
快速分析
多种数据源
弹性扩展
注册