FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(builder): preserve whitespace between SELECT and UNION body in CREATE VIEW (#655) by SAY-5 · Pull Request #657 · phpmyadmin/sql-parser · GitHub

fix(builder): preserve whitespace between SELECT and UNION body in CREATE VIEW (#655) - #657

Open
SAY-5 wants to merge 2 commits into
phpmyadmin:masterfrom
SAY-5:fix/issue-655-create-view-union-whitespace
Open

fix(builder): preserve whitespace between SELECT and UNION body in CREATE VIEW (#655)#657
SAY-5 wants to merge 2 commits into
phpmyadmin:masterfrom
SAY-5:fix/issue-655-create-view-union-whitespace

Conversation

SAY-5 commented Apr 30, 2026
edited
Loading

Copy link
Copy Markdown

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

SAY-5 commented Aug 23, 2026

Copy link
Copy Markdown
Author

Bumping this. The builder currently glues SELECT straight onto the UNION body so the rebuilt query comes back malformed, patch just keeps the space.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing space before UNION when building CREATE VIEW

1 participant


Back | FazBrowse Home | New Git URL