sqlsql-serverazureazure-synapsesql-data-warehouse

Aggregate strings in Azure SQL Data Warehouse


Is there a way to aggregate strings in Azure SQL Data Warehouse similar to the string_agg function in SQL Server?

I have records with strings that I want to concatenate into a single string.

SELECT string_agg(string_col, ',') FROM table1

https://learn.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql


Solution

  • Update Jan 2019: As at Jan 2019 STRING_SPLIT is available in SQL Data Warehouse as per here.

    Update Jul 2019: As at Jul 2019 STRING_AGG is available in SQL Data Warehouse as per here.

    Azure SQL Data Warehouse is an MPP system designed to hold billions of records and terabytes of data, so as a first port of call you should strongly consider if it's the right place to do string manipulation. It's also kind of expensive depending on what DWU you are running at. Have a read through this anti-patterns article.

    Azure SQL Data Warehouse Workload Patterns and Anti-Patterns https://blogs.msdn.microsoft.com/sqlcat/2017/09/05/azure-sql-data-warehouse-workload-patterns-and-anti-patterns/

    If you really need to do this in your warehouse then I did do a recent example specifically for Azure SQL Data Warehouse using a procedural approach:

    Does Azure SQL Data Warehouse have a way to split strings?