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

Support UNION queries that share a CTE #32

Open
jalaziz opened this issue Jun 14, 2021 · 2 comments
Open

Support UNION queries that share a CTE #32

jalaziz opened this issue Jun 14, 2021 · 2 comments

Comments

@jalaziz
Copy link

jalaziz commented Jun 14, 2021

I would like to write queries of the form:

WITH cte AS (SELECT * FROM ....)
(SELECT * FROM cte WHERE ...
UNION
SELECT * FROM cte WHERE ...)

Unfortunately, it seems that when trying to build such a query, the WITH clause is no added to the query. I believe this is due to the first if clause in CTECompiler. generate_sql.

I'm happy to put up a PR to remove the clause and attempt to make it work, but curious if there's a more fundamental not adding the WITH clause to queries with combinations?

@millerdev
Copy link
Contributor

I don't see a test that covers that scenario, and I can't remember if there is a workaround for queries with a combinator. That if clause should have probably raised NotImplementedError rather than returning as_sql(). But maybe that would have caused issues elsewhere?

A PR would be welcome. Please add tests as well.

@gjones-r7
Copy link

Oh, I need this too! This is a handy library.

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

3 participants