"Cursor" and "FOR XML" clause in Azure data warehouse

534 views Asked by At

While creating stored procedures in Azure data warehouse, I have got some error on "Cursor" and "FOR XML". So wanted to know if they are supported by Azure data warehouse or not. If not then what are the alternatives.

sample code with error msg pictures are attached herein.

enter image description here

enter image description here

1

There are 1 answers

0
wBob On

Neither FOR XML or cursors are supported in Azure Synapse dedicated SQL pools (formerly known as Azure SQL Data Warehouse) as per the documentation. For cursors, either convert them to use a WHILE loop which is supported or refactor the code to use a set-based approach. Another alternative is to use something external, like Azure Data Factory or Synapse Pipelines and use a For Each loop. Another alternative is to use a nearby Azure SQL DB to do some pre-processing. You should be aware the the MPP architecture of Azure Synapse Analytics does not lend itself well to this kind of row-based processing and you should remember it's a big data platform meant for large volumes of data, millions, billions of rows and set-based approaches should be preferred.

If you are just using FOR XML to do that sleazy string concatenation trick then you should use STRING_AGG instead which is fully supported in Synapse. See this answer for a recent example. If you are actually producing XML then you will need to find an alternative method, eg a nearby Azure SQL DB.