TRIM_ARRAY

The TRIM_ARRAY function returns a copy of the array argument from which the specified number of elements have been removed from the end of the array.

Read syntax diagramSkip visual syntax diagramTRIM_ARRAY( array-variable-name,numeric-constantnumeric-variable )
array-variable-name
Identifies an SQL variable or parameter. The variable or parameter must be an array type.
numeric-constant or numeric-variable
Specifies the number of elements that will be trimmed from the copy of array-variable-name. This must be a constant or SQL variable or parameter that can be cast to the integer data type. The value must be between 0 and the cardinality of array-variable-name.

The result array type is identical to the array type of the first argument but with the cardinality decreased by the number of elements trimmed.

The result can be null; if either argument is null, the result is the null value.

TRIM_ARRAY can only be used in an SQL procedure or SQL function as the only expression on the right side of an assignment-statement.

Note

Start of changeSyntax alternatives: ARRAY_TRIM can be specified as a synonym for TRIM_ARRAY.End of change

Example

Assume that array type PHONENUMBERS and array variable RECENT_CALLS are defined as follows:

CREATE TYPE PHONENUMBERS AS INTEGER ARRAY[50];
DECLARE RECENT_CALLS PHONENUMBERS;

The following statement removes the last element from the array variable RECENT_CALLS.

  SET RECENT_CALLS = TRIM_ARRAY(RECENT_CALLS, 1)