I have been using the LISTAGG function in Snowflake to concatenate strings and I triggered the following warning:
100078 (22000): String '(LISTAGG result)' is too long and would be truncated
I understand that this warning is triggered when the aggregated string exceeds a certain length. I want to know the best practices to prevent or handle this warning, given that truncation is fine and not relevant for the quality of column. Should I truncate in advance the result? If so, how?
SELECT
userid,
NULLIF(LISTAGG(DISTINCT city, ', '), '') AS cities,
NULLIF(LISTAGG(DISTINCT region, ', '), '') AS regions,
...
FROM {{ ref('myschema.table_T') }}
GROUP BY userid
Since the aggregates string reach the limit, you can't use the
LISTAGG
function. You could create a user-defined aggregate function instead :You can use it like this :
Inspired from this answer :