0

I am trying to implement a dataflow in Azure Data Factory (similar the workflow described in the answer on this question) which uses a custom SQL-query containing a WITH-statement, as a source (querying an Azure SQL DB), like:

WITH a AS (
    SELECT
    --magic
)

SELECT
    ...
FROM a
    ...

which leads to an "incorrect syntax" error in ADF

However specifying the subquery in the FROM statement like:

SELECT ...
FROM (
    SELECT
    --magic
) AS a
...

works fine, but is arguably not as readable/comprehensible (especially with multiple stacked subqueries).

Another workaround is taking the subquery from the WITH-statement, and moving it to a separate transformation-step in ADF altogether; however for lots of small subqueries this will create quite a bit of overhead/intransparency.

Which begs the question: are WITH-statements possible in ADF, and even if so, what are the exact SQL-syntax rules which ADF allows?

The only thing I can find in the Data Flow docs, is that ORDER BYs are not allowed, but no mention of other restrictions that might apply; separate questions here on Stackoverflow suggest that fore example recursive queries are also not supported.

Would be glad for some pointers, thanks!

4
  • 2
    Did you terminate your statement properly prior to the CTE declaration? I would assume not. Commented Aug 3, 2021 at 10:51
  • I am not sure what you mean here, could you elaborate? Commented Aug 3, 2021 at 13:29
  • I think he means adding a ";" at the beginning to terminate eventual other statements, Commented Apr 2, 2024 at 15:35
  • stackoverflow.com/questions/68714842/… this helped me. Commented Apr 2, 2024 at 15:37

1 Answer 1

0

I tried to reproduce the issue with some sample data in my Azure SQL Database and then using it as source dataset in my data flow. The same error has been observed. I tried with adding ; and go keywords at the starting of the query but still got the same error.

Although, you can reference a user-defined function, so you could nest your CTE inside a UDF and then reference that from Source Options.

Please find a workaround available here: Why Synapse is not working with my query?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.