mirror of
https://github.com/doctrine/dbal.git
synced 2026-03-23 22:32:15 +01:00
<!-- Fill in the relevant information below to help triage your pull request. --> | Q | A |------------- | ----------- | Type | bug | Fixed issues | #7318 #### Summary <!-- Provide a summary of your change. --> Technically this change adopts the solution for adding the CTE with parts to a SELECT query for UNION query handling using the `WithSQLBuilder` in case with parts has been set to allow creating queries like ```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) ``` using the `union` and `with` api on the same level: ```php $qb = $connection->createQueryBuilder(); $cte = $qb->sub() ->select('*') ->from('a_table'); $union1 = $qb->sub() ->select('cte_a.*', $qb->expr()->literal('lit1')) ->from('cte_a'); $union1 = $qb->sub() ->select('cte_a.*', $qb->expr()->literal('lit2')) ->from('cte_a'); $qb->with('cte_a', $cte) ->union($union1) ->addUnion($union2); ``` 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.