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

cardinality

1. CARDINALITY Function

======= cardinality | H2 Function | SQLDoc

cardinality

1. CARDINALITY Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The CARDINALITY function in H2 database is used to determine the number of elements in an array or a multiset.

2. Syntax

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

CARDINALITY(array_expression)

Arguments

  • array_expression: The array or multiset for which the cardinality needs to be calculated.

Return

  • The CARDINALITY function returns the number of elements in the given array or multiset.

3. Notes

  • The CARDINALITY function in H2 database only supports arrays and multisets. It does not support other data types.
  • If the input array or multiset is NULL, the CARDINALITY function will return NULL.
  • If the input array or multiset is an empty collection, the CARDINALITY function will return 0.
  • Make sure to provide a valid array or multiset expression to the CARDINALITY function to avoid errors.

4. Examples

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

Example 1 - Calculating the cardinality of an array:

SELECT CARDINALITY(ARRAY[1, 2, 3, 4, 5]) AS count;

Output:

count
-----
5

Example 2 - Calculating the cardinality of a multiset:

SELECT CARDINALITY(MULTISET[1, 2, 2, 3, 3, 3]) AS count;

Output:

count
-----
6

Example 3 - Calculating the cardinality of an empty array:

SELECT CARDINALITY(ARRAY[]) AS count;

Output:

count
-----
0

There are no related functions specifically related to the CARDINALITY function in H2 database.