- Categories:
Semi-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() | |-------------------| | [] | +-------------------+