Make it possible to create union main part for a CTE#7326
Merged
derrabus merged 1 commit intodoctrine:4.4.xfrom Mar 3, 2026
Merged
Make it possible to create union main part for a CTE#7326derrabus merged 1 commit intodoctrine:4.4.xfrom
derrabus merged 1 commit intodoctrine:4.4.xfrom
Conversation
This change modifies the internal handling of
`QueryBuilder` to prepand the CTE `with` parts
to allow creating valid union main parts like
following plain SQL:
```sql
WITH
-- CTE with parts
cte_a AS (SELECT * FROM a_table)
-- CTEmain part
(SELECT cte_a.*, 'lit1' from cte_a)
UNION (SELECT cte_a.*, 'lit2' from cte_a)
```
Resolves: doctrine#7318
1f8e64d to
160c3b2
Compare
derrabus
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Technically this change adopts the solution for adding
the CTE with parts to a SELECT query for UNION query
handling using the
WithSQLBuilderin case with partshas been set to allow creating queries like
using the
unionandwithapi on the same level:This is a valid use-case and supported by databases supporting
common table expressions albeit I could not find that documented
in any documentation and real world use-cases exists and is the
reason why this change has been considered as bugfix.