ARRAY
Description
The array
function is used to create an array containing specified elements. This function accepts any number of arguments and treats them as elements of the array. All elements will be arranged in the order they are passed in.
Parameter Description
e1, e2, ... eN
: TypeT
, can be any values of the same type. If values of different types are passed in, the system will attempt implicit type conversion.
Return Type
- Returns an array of type
array<T>
, whereT
is the specific type of the elements.
Usage Example
- Create an array containing integers:
- Create an array containing floating point numbers:
- Create an array containing strings:
- Implicit Type Conversion Example:
- Use the
array
function in combination with theSELECT
statement to select multiple fields from the table and create an array:
Assuming my_table
contains three columns column1
, column2
, column3
, this query will return an array containing the values of these three columns for each row.
Notes
- When the types of the input parameters are inconsistent, the system will attempt implicit type conversion. If the conversion fails, the element will be returned as null.
- When creating arrays, ensure that all elements are type-compatible to avoid unnecessary type conversions and potential performance loss.
By using the array
function, you can easily create and manage array data in SQL queries, allowing for more flexible handling and analysis of datasets.