Start of change

CARDINALITY

The CARDINALITY function returns a value representing the number of elements of an array.

Read syntax diagramSkip visual syntax diagram
>>-CARDINALITY--(--array-expression--)-------------------------><

array-expression
The expression can be either an SQL procedure variable or parameter of an array data type, or a cast specification of a parameter marker to an array data type.

The value returned by the CARDINALITY function is the highest subindex for which the array has an assigned element. This includes elements that have been assigned the null value.

The result of the function is BIGINT. The function returns 0 if the array is empty. The result can be null; if the argument is null, the result is the null value.

Example

Assume that type INT_ARRAY is defined as:

CREATE TYPE INT_ARRAY AS INTEGER ARRAY[100]
The SET statement in the following code fragment assigns variable LEN the value 4.
BEGIN
  DECLARE LEN INTEGER;
  DECLARE MYARRAY INT_ARRAY;

  SET MYARRAY = ARRAY[0,0,1,1];
  SET LEN = CARDINALITY(MYARRAY);
END   
End of change