Array Positions
Definition
The arrayPositions
method allows you to add the ARRAY_POSITIONS
function to the query. The ARRAY_POSITIONS
function is used to returns an array of subscripts of all occurrences of the second argument in the array given as first argument (array must be one-dimensional).
Available methods
arrayPositions(KColumn kColumnArray, KColumn kColumnElement)
: Receives twoKColumn
orKTableColumn
which will be supplied to theARRAY_POSITIONS
function.arrayPositions(KColumn kColumnArray, Object element)
: Receives aKColumn
orKTableColumn
and anObject
value which will be supplied to theARRAY_POSITIONS
function.
To use this way, you need to import the static functions as follows:
import static com.myzlab.k.KFunction.*;
Example: (KColumn, KColumn)
Java code:
k
.select(
arrayPositions(arrayAgg(APP_USER.FIRST_NAME), APP_USER.LAST_NAME),
APP_USER.CREATED_AT.cast(date())
)
.from(APP_USER)
.groupBy(APP_USER.CREATED_AT.cast(date()), APP_USER.LAST_NAME)
.multiple();
SQL generated:
SELECT
ARRAY_POSITIONS(ARRAY_AGG(au.first_name), au.last_name),
CAST(au.created_at AS DATE)
FROM app_user au
GROUP BY CAST(au.created_at AS DATE), au.last_name
Parameters:
- None
Example: (KColumn, Object)
Java code:
k
.select(
arrayPositions(arrayAgg(APP_USER.EMAIL), "EOF"),
APP_USER.CREATED_AT.cast(date())
)
.from(APP_USER)
.groupBy(APP_USER.CREATED_AT.cast(date()))
.multiple();
SQL generated:
SELECT
ARRAY_POSITIONS(ARRAY_AGG(au.email), ?1),
CAST(au.created_at AS DATE)
FROM app_user au
GROUP BY CAST(au.created_at AS DATE)
Parameters:
- ?1: "EOF"