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

Add support for combination two CTE queries #59

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pgammans
Copy link
Contributor

@pgammans pgammans commented Jul 6, 2022

This is an initial draft/ RFC commit that provides support merging queries with CTEs on both sides.
Initial support is for (union, difference, and difference) operators | and & are not as yet supported by may be possible to implement as a union wrapped in a CTE to allow Django to continue to apply filters an other ops.

ie allowing
combined_ctequery = cte_query1.union(cte_query2, cte_query3)

Basic premise is to:

  • move all CTEs to the first or master query in the set.
  • renames the CTEs if there are naming conflicts conflicts. (I'm not 100% happy with this )

More work will be needed to improve..

  • the limited test coverage. Any help or real example here appreciated.
  • identification of identical CTEs (atm we use == to test for equality i.e. same object. This is correct but not means two identical CTE but not the same object will both be added, this means that the resultant SQL is less optimal )
  • I dont like renaming the CTE but as this may affect raw CTEs and raw sql_extras

This may solve #32

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

Successfully merging this pull request may close these issues.

1 participant