New versions: Dev (3.16) | Latest (3.15) | 3.14

CARDINALITY

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The CARDINALITY function allows for getting the size of an array.

SELECT CARDINALITY(ARRAY[1, 2])
create.select(cardinality(array(1, 2))).fetch();

The result would look like this:

+-------------+
| cardinality |
+-------------+
|           2 |
+-------------+

Dialect support

This example using jOOQ:

cardinality(array(1, 2))

Translates to the following dialect specific expressions:

-- AURORA_POSTGRES, H2, HSQLDB, POSTGRES
cardinality(ARRAY[1, 2])

-- ACCESS, ASE, AURORA_MYSQL, BIGQUERY, COCKROACHDB, DB2, DERBY, EXASOL, FIREBIRD, HANA, IGNITE, INFORMIX, MARIADB, MEMSQL, 
-- MYSQL, ORACLE, REDSHIFT, SNOWFLAKE, SQLDATAWAREHOUSE, SQLITE, SQLSERVER, SYBASE, TERADATA, VERTICA
/* UNSUPPORTED */

(These are currently generated with jOOQ 3.16, see #10141), or translate your own on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo