<<<<<<< HEAD array_max_cardinality | H2 | SQLDoc
Skip to main content

array_max_cardinality

1. ARRAY_MAX_CARDINALITY Function

======= array_max_cardinality | H2 Function | SQLDoc

array_max_cardinality

1. ARRAY_MAX_CARDINALITY Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ARRAY_MAX_CARDINALITY function in H2 database is used to determine the maximum cardinality of an array expression.

2. Syntax

The syntax for the ARRAY_MAX_CARDINALITY function in H2 database is as follows:

ARRAY_MAX_CARDINALITY(array_expression)

Arguments

  • array_expression: The array expression for which the maximum cardinality needs to be determined.

Return

  • The ARRAY_MAX_CARDINALITY function returns the maximum cardinality of the given array expression.

3. Notes

  • The ARRAY_MAX_CARDINALITY function in H2 database is particularly useful when dealing with arrays or nested arrays.
  • It helps determine the maximum number of elements in an array expression.
  • If the input expression is not an array or if it is NULL, the function will return NULL.
  • The ARRAY_MAX_CARDINALITY function is supported starting from H2 version 1.4.200.

4. Examples

Here are a few examples demonstrating the usage of the ARRAY_MAX_CARDINALITY function in H2 database:

Example 1 - Determining the maximum cardinality of a simple array:

SELECT ARRAY_MAX_CARDINALITY(ARRAY[1, 2, 3, 4, 5]) AS max_cardinality;

Output:

max_cardinality
---------------
5

Example 2 - Determining the maximum cardinality of an array stored in a column:

CREATE TABLE arrays (
id INT PRIMARY KEY,
values ARRAY
);

INSERT INTO arrays VALUES (1, ARRAY[10, 20, 30]), (2, ARRAY[40, 50, 60, 70]);

SELECT id, values, ARRAY_MAX_CARDINALITY(values) AS max_cardinality
FROM arrays;

Output:

id |        values       | max_cardinality
---+---------------------+----------------
1 | [10,20,30] | 3
2 | [40,50,60,70] | 4
  • cardinality - Determine the number of elements in an array