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

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.

Kotlin ARRAY access

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

Array elements can be accessed using the ARRAY_GET function, which translates to the ARRAY subscript syntax:

SELECT (ARRAY[1, 2])[1]
create.select(arrayGet(array(1, 2), 1)).fetch();

Using the kotlin extensions module, these operators are also made available on Field<Array<T>> directly:

package org.jooq.kotlin

operator fun <T> Field<Array<T>?>.get(index: Int) = arrayGet(this, index)
operator fun <T> Field<Array<T>?>.get(index: Field<Int>) = arrayGet(this, index)

// [... and more]

This allows for the leaner version below:

create.select(array(1, 2)[1]).fetch();

Feedback

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

The jOOQ Logo