Available in versions: Dev (3.21) | Latest (3.20)

POSITION (binary)

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The POSITION() function finds the first position of a binary string within another binary string, starting with 1.

SELECT
  position(cast('hello' as bytea), cast('e' as bytea)),
  position(cast('hello' as bytea), cast('l' as bytea), 4);
create.select(
  binaryPosition("hello".getBytes(), "e".getBytes()),
  binaryPosition("hello".getBytes(), "e".getBytes(), 4)).fetch();

The result being

+----------+----------+
| position | position |
+----------+----------+
|        2 |        4 |
+----------+----------+
See POSITION for a text version of this function.

Dialect support

This example using jOOQ:

binaryPosition("hello".getBytes(), "e".getBytes())

Translates to the following dialect specific expressions:

Aurora Postgres, CockroachDB, Postgres, YugabyteDB

position(CAST(E'\\145' AS bytea) IN CAST(E'\\150\\145\\154\\154\\157' AS bytea))

Databricks

position(X'65' IN X'68656C6C6F')

Redshift

position(from_hex('65') IN from_hex('68656C6C6F'))

ASE, Access, Aurora MySQL, BigQuery, ClickHouse, DB2, Derby, DuckDB, Exasol, Firebird, H2, HSQLDB, Hana, Informix, MariaDB, MemSQL, MySQL, Oracle, SQLDataWarehouse, SQLServer, SQLite, Snowflake, Spanner, Sybase, Teradata, Trino, Vertica

/* 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!

The jOOQ Logo