Missing space before UNION when building CREATE VIEW
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start at CreateStatement::build() and reproduce the issue with the SQL example through PhpMyAdmin\SqlParser\Parser. Verify that rebuilding the CREATE VIEW preserves whitespace before the trailing UNION body and produces valid SQL rather than 3union all.
Written by the indexing model from the issue text.
Description
Summary
When CreateStatement::build() reconstructs a CREATE VIEW ... AS SELECT ... UNION ...
statement, the output misses the whitespace between the built SELECT and the
trailing body tokens. Result: invalid SQL such as ... WHERE 3 = 3union all (...).
This was previously reported downstream in phpMyAdmin:
- phpmyadmin/phpmyadmin#19692
- phpmyadmin/phpmyadmin#18515 (same bug, older)
Reproduction
use PhpMyAdmin\SqlParser\Parser;
$sql = "CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER "
. "VIEW `v1` AS select 1 AS `a` where 3 = 3 union all (select 2 AS `a`)";
echo (new Parser($sql))->statements[0]->build();
Actual output:
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS SELECT 1 AS `a` WHERE 3 = 3union all (select 2 AS `a`)
(note: 3 = 3union all — no space).
Expected: a space before union all, producing valid SQL.
Environment
- Library version: current
master(headf440917e) - PHP: 8.4
- Dominant language
- PHP
- Stars
- 485
- Forks
- 119
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpmyadmin/sql-parser
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
phpmyadmin/sql-parser#666 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
phpmyadmin/sql-parser#662 · 2 reactions ·
-
kind/support
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpmyadmin/sql-parser#653 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
phpmyadmin/sql-parser#649 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 25/100
phpmyadmin/sql-parser#643 · 1 comment ·
All issues in phpmyadmin/sql-parser
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·