ARRAY constructor

The ARRAY constructor returns an array specified by a list of expressions or a fullselect.

Read syntax diagramSkip visual syntax diagramARRAY[ fullselect,element-expression ]
fullselect
A fullselect that returns a single column. The values returned by the fullselect are the elements of the array. The cardinality of the array is equal to the number of rows returned by the fullselect. An ORDER BY clause in the fullselect can be used to specify the order among the elements of the array; otherwise, the order is undefined. Start of change The attributes of the base type of the array are the same as the data type of the result column of the fullselect.End of change
element-expression
An expression defining the value of an element within the array. The cardinality of the array is equal to the number of element expressions. The first element-expression is assigned to the array element with Start of changearray indexEnd of change 1. The second element-expression is assigned to the array element with Start of changearray indexEnd of change 2, and so on. All element expressions must have compatible data types. Start of changeThe attributes of the base type of the array are determined by all the operands as explained in Rules for result data types.End of change

If there is no expression within the brackets, the result is an empty array. The cardinality of an empty array is 0.

An ARRAY constructor can only be specified on the right side of a SET variable or assignment-statement.

Examples

  • Set the array variable RECENT_CALLS of array type PHONENUMBERS to an array of fixed numbers.
    SET RECENT_CALLS = ARRAY[9055553907, 4165554213, 4085553678]
  • Set the array variable DEPT_PHONES of array type PHONENUMBERS to an array of phone numbers retrieved from the DEPARTMENT_INFO table.
    SET DEPT_PHONES = ARRAY[SELECT DECIMAL(AREA_CODE CONCAT ’555’ CONCAT EXTENSION,16)
    																	       FROM DEPARTMENT_INFO
    																	       WHERE DEPTID = 624]