Karl Azzam
04/10/2024, 6:13 PMSELECT
u.id AS user_id,
ARRAY_AGG(ua.entity_path) AS paths
FROM
foo_schema.user_table u
JOIN
foo_schema.user_attributes_table ua ON u.id = ua.user_id
GROUP BY
u.id
I instead am doing this where i get multiple rows per user for each user's entity path.
SELECT
u.id AS user_id,
ua.entity_path AS path
FROM
foo_schema.user_table u
JOIN
foo_schema.user_attributes_table ua ON u.id = ua.user_id
GROUP BY
u.id, ua.entity_path
Chantal Loncle
04/11/2024, 1:26 AMclass ArrayAggFunction<T>(
expression: ExpressionWithColumnType<T>,
delegate: ColumnType
) : CustomFunction<List<T>>(
functionName = "ARRAY_AGG",
columnType = ArrayColumnType(delegate),
expr = arrayOf(expression)
)
The argument passed to delegate
should be the matching ColumnType
used for the ua.entity_path
column. An instance of this function could then be provided to select()
in the join query:
// for example, if entity_path stored strings using varchar()
val pathAgg = ArrayAggFunction(UserAttributeTable.entityPath, VarCharColumnType())
val join = // ...
join
.select(UserTable.id, pathAgg)
.groupBy(UserTable.id)
.map { }
Karl Azzam
04/11/2024, 12:31 PM