GeezerVison is showing github.com — fix(builder): preserve whitespace between SELECT and UNION body in CREATE VIEW (#655) by SAY-5 · Pull Request #657 · phpmyadmin/sql-parser
Conversation
SAY-5
commented
Apr 30, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Fixes #655. CreateStatement::build() reconstructed CREATE VIEW ... AS SELECT ... UNION ... by concatenating $builtStatement = $this->select->build() directly with TokensList::buildFromArray($this->body). Neither side carried a separator, so the rebuilt SQL collided the SELECT's last token with the UNION:
... WHERE 3 = 3union all (...)
This was reported downstream in phpmyadmin/phpmyadmin#19692 (and earlier as #18515), the syntax-invalid output broke phpMyAdmin's exports.
Change
src/Statements/CreateStatement.php, insert a single space when both sides are non-empty and neither already ends/begins with a space. The existing WITH ... AS ( ... ) SELECT ... path already produces a trailing space on $builtStatement, so the conditional avoids double-spacing it.
Test plan
-
vendor/bin/phpunit tests/Builder/, 110/110 pass (including the existing testBuilderView which already exercised UNION on a different shape)
- New
testBuilderViewWithUnionPreservesWhitespace reproducing the issue's exact CREATE ALGORITHM=UNDEFINED ... AS select 1 AS \`a\` where 3 = 3 union all (...) input. Asserts:
- rebuilt SQL does not contain
3union all (collision)
- rebuilt SQL does contain
3 union all (case-normalised)
- Existing WITH+UNION test (
CREATE view view_name AS WITH aa(col1) AS (...) SELECT ...) unchanged, the conditional separator preserves its prior trailing-space output
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Bumping this. The builder currently glues SELECT straight onto the UNION body so the rebuilt query comes back malformed, patch just keeps the space.
|
williamdes reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you !
And thank you for adding a test
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.