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_ANY_MATCH

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

The ARRAY_ANY_MATCH function allows for checking if any of the 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_any_match(ARRAY[1, 2, 2, 3], e -> e > 2)
create.select(arrayAnyMatch(array(1, 2, 2, 3), e -> e.gt(2))).fetch();

The result would look like this:

+-----------------+
| array_any_match |
+-----------------+
| true            |
+-----------------+

Dialect support

This example using jOOQ:

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

Translates to the following dialect specific expressions:

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

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

BigQuery

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 e > 2
)

ClickHouse

arrayExists(
  e -> e > 2,
  ARRAY(1, 2, 2, 3)
)

Trino

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

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