I know the LISTAGG function is in the <Unsuppoted ...
# suiteql
b
I know the LISTAGG function is in the Unsuppoted Functions list. But sometimes it works, and other times it gives a syntax error. Does anyone know of a work-around or alternative?
j
I was like….CONVINCED it didn’t work for ages and wrote a complex chunk of SQL to make a bitmask and turn that into my equivalent. Was a pain in the butt. The last few times I’ve tried LISTAGG it has worked tho.
w
Make sure you use ”on overflow truncate” as it can fail if any value becomes longer than 3-4000 characters.
b
@Watz -- how do you specify ”on overflow truncate”?
w
Copy code
LISTAGG(TL.uniqueKey, ',' ON OVERFLOW TRUNCATE '...' WITHOUT COUNT) WITHIN GROUP(ORDER BY TL.uniqueKey)
👍 1
s
Full example:
Copy code
WITH t2 AS (
  SELECT     transaction.id AS transaction_id, transactionline.uniquekey
  FROM       transaction
  INNER JOIN transactionline ON (transactionline.transaction = transaction.id)
  FETCH FIRST 1000 ROWS ONLY
)
SELECT   t2.transaction_id,
         LISTAGG(t2.uniquekey, ', ' ON OVERFLOW TRUNCATE '...' WITHOUT COUNT)
         WITHIN GROUP (ORDER BY t2.uniquekey) AS transactionline_uniquekeys
FROM     t2
GROUP BY t2.transaction_id
ORDER BY t2.transaction_id