Available in versions: Dev (3.21) | Latest (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11
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.
CONTAINS predicate
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
CONTAINS predicates allow for finding strings by a common, fixed infix.
Unlike the LIKE predicate (which can be used to emulate this), no wildcards are supported and the infix must be matched exactly.
With jOOQ, the CONTAINS predicate can be created from any column expression as such:
CONTAINS(TITLE, 'abc')
BOOK.TITLE.contains("abc")
Dialect support
This example using jOOQ:
BOOK.TITLE.contains("abc")
Translates to the following dialect specific expressions:
ASE
BOOK.TITLE LIKE ('%' || str_replace(
str_replace(
str_replace('abc', '!', '!!'),
'%',
'!%'
),
'_',
'!_'
) || '%') ESCAPE '!'
Aurora MySQL, MariaDB, MySQL
BOOK.TITLE LIKE concat(
'%',
replace(
replace(
replace('abc', '!', '!!'),
'%',
'!%'
),
'_',
'!_'
),
'%'
) ESCAPE '!'
Aurora Postgres, CockroachDB, Firebird, H2, HSQLDB, Hana, Informix, Oracle, Postgres, SQLite, Sybase, Vertica
BOOK.TITLE LIKE ('%' || replace(
replace(
replace('abc', '!', '!!'),
'%',
'!%'
),
'_',
'!_'
) || '%') ESCAPE '!'
BigQuery, Spanner
strpos(BOOK.TITLE, 'abc') > 0
Databricks, DuckDB
contains(BOOK.TITLE, 'abc')
DB2
BOOK.TITLE LIKE CAST(('%' || replace(
replace(
replace('abc', '!', '!!'),
'%',
'!%'
),
'_',
'!_'
) || '%') AS VARCHAR(4000)) ESCAPE '!'
SQLDataWarehouse
charindex('abc', BOOK.TITLE) > 0
SQLServer
BOOK.TITLE LIKE ('%' + replace(
replace(
replace('abc', '!', '!!'),
'%',
'!%'
),
'_',
'!_'
) + '%') ESCAPE '!'
Access, ClickHouse, Exasol, MemSQL, Redshift, Snowflake, Teradata, Trino, YugabyteDB
/* UNSUPPORTED */
Generated with jOOQ 3.21. Support in older jOOQ versions may differ. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!