- Categories:
Semi-structured and structured data functions (Array/Object)
ARRAY_CONSTRUCT¶
Returns an array constructed from zero, one, or more inputs.
- See also:
Syntax¶
ARRAY_CONSTRUCT( [ <expr1> ] [ , <expr2> [ , ... ] ] )
Arguments¶
The arguments are values (or expressions that evaluate to values). The arguments do not all need to be of the same data type.
Returns¶
The data type of the returned value is ARRAY
.
Usage notes¶
The data types of the inputs may vary.
If the function is called with
N
arguments, the size of the resulting array will beN
.In many contexts, you can use an ARRAY constant (also called an ARRAY literal) instead of the ARRAY_CONSTRUCT function.
Examples¶
Construct a basic array consisting of numeric data types:
SELECT ARRAY_CONSTRUCT(10, 20, 30); +-----------------------------+ | ARRAY_CONSTRUCT(10, 20, 30) | |-----------------------------| | [ | | 10, | | 20, | | 30 | | ] | +-----------------------------+
Construct a basic array consisting of different data types:
SELECT ARRAY_CONSTRUCT(null, 'hello', 3::double, 4, 5); +-------------------------------------------------+ | ARRAY_CONSTRUCT(NULL, 'HELLO', 3::DOUBLE, 4, 5) | |-------------------------------------------------| | [ | | undefined, | | "hello", | | 3.000000000000000e+00, | | 4, | | 5 | | ] | +-------------------------------------------------+
Construct an empty array:
SELECT ARRAY_CONSTRUCT(); +-------------------+ | ARRAY_CONSTRUCT() | |-------------------| | [] | +-------------------+