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

WITH RECURSIVE is only allowed at the top level #198

Open
jameshorrocks001 opened this issue Jan 16, 2024 · 4 comments
Open

WITH RECURSIVE is only allowed at the top level #198

jameshorrocks001 opened this issue Jan 16, 2024 · 4 comments
Labels
question Further information is requested

Comments

@jameshorrocks001
Copy link

jameshorrocks001 commented Jan 16, 2024

Getting the following error when trying to run unit tests with model having a recursive CTE

Runtime Error
  Database Error in model_example (tests/unit/model_example.sql)
    WITH RECURSIVE is only allowed at the top level of the SELECT, CREATE TABLE AS SELECT, CREATE VIEW, INSERT, EXPORT DATA statements.

Within the generated test SQL, the recursive CTE is no longer at the top level which invalidates the query.

Is there a way to handle this?

@psousa50
Copy link
Collaborator

Hi @jameshorrocks001, I'm afraid this will be a tough one. 'dbt-unit-testing' relies heavily on CTEs and it's hard to make it work if you can only have recursive CTEs at the top level. Which database are you using?

@psousa50 psousa50 added the question Further information is requested label Jan 19, 2024
@jameshorrocks001
Copy link
Author

Hi, we're using Big Query

@psousa50
Copy link
Collaborator

Hi @jameshorrocks001,

Sorry for the late response. I'm afraid it's not possible right now to use recursive CTEs with dbt-unit-testing. Thank you very much for your comment; we'll try to think of a way to solve this.

@cdiniz
Copy link
Collaborator

cdiniz commented Apr 18, 2024

We should note this as a limitation of our current approach.
Since we create a CTE for mocking purposes - the model under test will always be inside this top-level CTE.

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

No branches or pull requests

3 participants