Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: support OPTION( MAXRECURSION <INT> ) for recursive CTE's #104

Open
JustGitting opened this issue Jul 13, 2024 · 0 comments

Comments

@JustGitting
Copy link

I'm migrating some existing SQL code that uses recursive CTE with the option( MAXRECURSION 200) into DBT.

For example the original code is of the format (copied from https://www.sqlservertutorial.net/sql-server-basics/sql-server-recursive-cte/):

WITH expression_name (column_list)
AS
(
    -- Anchor member
    initial_query  
    UNION ALL
    -- Recursive member that references expression_name.
    recursive_query  
)
-- references expression name
SELECT *
FROM expression_name
OPTION( MAXRECURSION 200 )

However, even when I materialized the model as a table, I get the following error:

Incorrect syntax near the keyword 'OPTION'.

This is because the way DBT creates the model. DBT will create a view and then copy the results into a table.

If I remove option(MAXRECURSION, 200), then I get the following error when running DBT:

The statement terminated. The maximum recursion 100 has been exhausted before statement completion.

Could the OPTION() directive be supported in tsql-utils?
Or it is not possible due to the upstream limitation of DBT itself?

If this feature cannot be supported, is there a work-around?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant