Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

CASE with alias is not properly parsed

Open
#588 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
php, sql

Research direction

Start by reproducing the supplied CASE expression through the Parser and comparing the reported errors and build() output. Trace how CASE expressions consume aliases and keywords, then add a regression case showing that this SQL parses without errors and builds with the alias preserved correctly.

Written by the indexing model from the issue text.

Description

bug

Feeding this SQL to the Parser:

SELECT
  CASE 
    WHEN a.kol = 1 THEN 'one'
    ELSE a.kol
  END as 'case'
FROM foo a;

will result in errors, and calling build() on the statement will result in this SQL:

SELECT CASE 'case' ELSE a.kol AS `END` END FROM foo AS `a`

The errors array contains these errors:

  • An alias was previously found.
  • An alias was expected.
  • Unexpected keyword.
  • Unexpected end of CASE expression

I encountered this problem since I upgraded from 5.8.2 to 5.9.1.

Dominant language
PHP
Stars
485
Forks
119
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpmyadmin/sql-parser

All issues in phpmyadmin/sql-parser

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.