Array To String
Definition
The arrayToString method allows you to add the ARRAY_TO_STRING function to the query. The ARRAY_TO_STRING function is used to concatenates array elements using supplied delimiter and optional null string.
Available methods
arrayToString(KColumn kColumnArray, String delimiter): Receives aKColumnorKTableColumnand aStringvalue which will be supplied to theARRAY_TO_STRINGfunction.arrayToString(KColumn kColumnArray, String delimiter, String nullString): Receives aKColumnorKTableColumnand twoStringvalues which will be supplied to theARRAY_TO_STRINGfunction.
To use this way, you need to import the static functions as follows:
import static com.myzlab.k.KFunction.*;
Example: (KColumn, String)
Java code:
k
.select(
arrayToString(arrayAgg(APP_USER.FIRST_NAME), ","),
APP_USER.CREATED_AT.cast(date())
)
.from(APP_USER)
.groupBy(APP_USER.CREATED_AT.cast(date()))
.multiple();
SQL generated:
SELECT
ARRAY_TO_STRING(ARRAY_AGG(au.first_name), ?1),
CAST(au.created_at AS DATE)
FROM app_user au
GROUP BY CAST(au.created_at AS DATE)
Parameters:
- ?1: ","
Example: (KColumn, String, String)
Java code:
k
.select(
arrayToString(arrayAgg(APP_USER.FIRST_NAME), ",", "*"),
APP_USER.CREATED_AT.cast(date())
)
.from(APP_USER)
.groupBy(APP_USER.CREATED_AT.cast(date()))
.multiple();
SQL generated:
SELECT
ARRAY_TO_STRING(ARRAY_AGG(au.first_name), ?1, ?2),
CAST(au.created_at AS DATE)
FROM app_user au
GROUP BY CAST(au.created_at AS DATE)
Parameters:
- ?1: ","
- ?1: "*"