Available in versions: Dev (3.20) | Latest (3.19) | 3.18

ARRAY_PREPEND (|| operator)

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

The ARRAY_PREPEND function allows for concatenating an element to the beginning of an array (see also ARRAY_APPEND and ARRAY_CONCAT):

SELECT 1 || ARRAY[2, 3]
create.select(arrayPrepend(1, array(2, 3))).fetch();

The result would look like this:

+--------------.+
| array_prepend |
+---------------+
| [1, 2, 3]     |
+---------------+

Dialect support

This example using jOOQ:

arrayPrepend(1, array(2, 3))

Translates to the following dialect specific expressions:

Aurora Postgres, CockroachDB, DuckDB, Postgres, YugabyteDB

array_prepend(
  1,
  ARRAY[2, 3]
)

ClickHouse

arrayPushFront(
  ARRAY(2, 3),
  1
)

H2, HSQLDB, Trino

(ARRAY[1] || ARRAY[2, 3])

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

/* UNSUPPORTED */

(These are currently generated with jOOQ 3.20, 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