CTE parsing fails when name is a non-reserved keyword
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
Direzione di ricerca
Inizia eseguendo i due riproduttori vendor/bin/sql-parser --lint --query e traccia il modo in cui lexer e parser gestiscono il nome del CTE dopo WITH, inclusi i nomi racchiusi tra backtick. Il lavoro è completato quando entrambe le query vengono analizzate correttamente, inclusi i nomi di parole chiave non riservate e i nomi di parole chiave tra virgolette, senza gli errori segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The parser rejects valid CTEs whose names are non-reserved keywords, throwing:
The name of the CTE was expected.
MySQL has a large set of keywords that are explicitly not reserved (no (R) marker in the official MySQL 9.7 keyword list^1). Non-reserved keywords are explicitly permitted as unquoted identifiers, including CTE names. MySQL executes these queries without error^2.
Reproducer
Unquoted:
vendor/bin/sql-parser --lint --query "WITH data AS (SELECT 1) SELECT * FROM data"
#1: The name of the CTE was expected. (near "data" at position 5)
#2: Unexpected end of the WITH CTE. (near "data" at position 5)
#3: Unrecognized statement type. (near "data" at position 5)
Backtick-quoted (which should unconditionally allow any keyword as an identifier):
vendor/bin/sql-parser --lint --query "WITH `data` AS (SELECT 1) SELECT * FROM `data`"
#1: The name of the CTE was expected. (near "`data`" at position 5)
#2: Unexpected end of the WITH CTE. (near "`data`" at position 5)
#3: Unexpected beginning of statement. (near "`data`" at position 5)
#4: Unrecognized statement type. (near "AS" at position 12)
Expected behaviour
The query parses successfully for any non-reserved keyword used as a CTE name, whether unquoted or backtick-quoted.
Actual behaviour
Parser throws errors in both cases. The root cause appears to be that the lexer classifies all keywords as keyword tokens unconditionally, rather than resolving them contextually. After WITH, the parser expects an identifier token; receiving a keyword token instead, it fails, even though MySQL allows non-reserved keywords in identifier position without quoting, and allows any keyword in identifier position when backtick-quoted.
- Lingua principale
- PHP
- Stelle
- 485
- Fork
- 119
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di phpmyadmin/sql-parser
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
phpmyadmin/sql-parser#655 · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
phpmyadmin/sql-parser#666 ·
-
MariaDB and MySQL contexts Apertakind/support
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
phpmyadmin/sql-parser#653 · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
phpmyadmin/sql-parser#649 ·
-
Support `PAGE_COMPRESSED`=1` Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
phpmyadmin/sql-parser#643 · 1 commento ·
Tutte le issue di phpmyadmin/sql-parser
Issue simili
-
sync-en
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
-
sync-en
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
-
Перевод устарел
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100