Available in versions: Dev (3.20)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

ARRAY_ALL_MATCH

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

The ARRAY_ALL_MATCH function allows for checking if all array elements match a given predicate.

A few SQL dialects, including ClickHouse, DuckDB, and Trino have introduced higher order functions with a lambda syntax to help implement features like this one. jOOQ can map a Java lambda to a SQL lambda, and emulate the feature using standard SQL functionality (using UNNEST and ARRAY_AGG) if the function isn't available.
SELECT array_all_match(ARRAY[1, 2, 2, 3], e -> e > 0)
create.select(arrayAllMatch(array(1, 2, 2, 3), e -> e.gt(0))).fetch();

The result would look like this:

+-----------------+
| array_all_match |
+-----------------+
| true            |
+-----------------+

Dialect support

This example using jOOQ:

arrayAllMatch(array(1, 2, 2, 3), e -> e.gt(0))

Translates to the following dialect specific expressions:

Aurora Postgres, CockroachDB, DuckDB, H2, HSQLDB, Postgres

(NOT EXISTS (
  SELECT 1 one
  FROM UNNEST(ARRAY[1, 2, 2, 3]) t (e)
  WHERE NOT (e > 0)
))

BigQuery

(NOT EXISTS (
  SELECT 1 one
  FROM (
    SELECT null e
    FROM UNNEST([STRUCT(1 AS dual)]) AS dual
    WHERE FALSE
    UNION ALL
    SELECT *
    FROM UNNEST(ARRAY[1, 2, 2, 3]) t
  ) t
  WHERE NOT (e > 0)
))

ClickHouse

arrayAll(
  e -> e > 0,
  ARRAY(1, 2, 2, 3)
)

Trino

all_match(
  ARRAY[1, 2, 2, 3],
  e -> e > 0
)

ASE, Access, Aurora MySQL, DB2, Derby, Exasol, Firebird, Hana, Informix, MariaDB, MemSQL, MySQL, Oracle, Redshift, SQLDataWarehouse, SQLServer, SQLite, Snowflake, Sybase, Teradata, Vertica, YugabyteDB

/* UNSUPPORTED */
Generated with jOOQ 3.20. Translate your own SQL on our website

Feedback

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

The jOOQ Logo