MAX_CARDINALITY scalar function

The MAX_CARDINALITY function returns a value of type BIGINT that represents the maximum number of elements that an array can contain. This value is the cardinality that was specified in the CREATE TYPE statement for an ordinary array type.

Read syntax diagramSkip visual syntax diagramMAX_CARDINALITY( array-expression)

The schema is SYSIBM.

array-expression
Start of changeAn SQL variable, SQL parameter, or global variable of an array type, or a CAST specification that specifies an SQL variable, SQL parameter, global variable, or parameter marker as the source value.End of change
The result of the MAX_CARDINALITY function is as follows:
  • For an ordinary array, the result is the maximum number of elements that an array can contain.
  • For an associative array, the result is the null value.

The data type of the result is BIGINT.

Start of changeIf the argument is an associative array, the result can be null and the result is the null value. Otherwise, the result cannot be null.End of change

Examples

Example 1: Suppose that array type PHONENUMBERS and array variable RECENT_CALLS are defined as follows:

CREATE TYPE PHONENUMBERS AS DECIMAL(10,0) ARRAY[50];
CREATE VARIABLE RECENT_CALLS PHONENUMBERS;

The following statement sets LIST_SIZE to the maximum cardinality with which RECENT_CALLS was defined.

SET LIST_SIZE = MAX_CARDINALITY(RECENT_CALLS);

After the statement executes, LIST_SIZE contains 50.