You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cannot parse ALTER TABLE ... DROP COLUMN command where type is the column name
TYPE is a non-reserved keyword in MySQL 8.0 (see MySQL keyword list), so ALTER TABLE nullable_tbl DROP COLUMN type; is valid MySQL syntax without any quoting
SQL Example:
ALTERTABLE nullable_tbl DROP COLUMN type;
fails with:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "type" "TYPE"
at line 1, column 38.
Was expecting one of:
"IF"
"NAME"
<S_IDENTIFIER>
<S_QUOTED_IDENTIFIER>
while the same identifier parses fine in other contexts:
SELECT type FROM nullable_tbl; -- OKALTERTABLE nullable_tbl DROP COLUMN `type`; -- OK (quoted)
Software Information:
JSQLParser 5.3 (also reproducible with current master: KeywordOrIdentifier() accepts K_NAME | K_NEXT | K_VALUE | K_PUBLIC | K_STRING | K_DATA but not K_TYPE)
For reference, other MySQL non-reserved words that currently fail in the same DROP COLUMN position on master: comment, action, position, format, domain (and the datatype-token family text, date, year, timestamp, which probably needs a different approach).
Failing SQL Feature:
ALTER TABLE ... DROP COLUMNcommand wheretypeis the column nameTYPEis a non-reserved keyword in MySQL 8.0 (see MySQL keyword list), soALTER TABLE nullable_tbl DROP COLUMN type;is valid MySQL syntax without any quotingSQL Example:
fails with:
while the same identifier parses fine in other contexts:
Software Information:
KeywordOrIdentifier()acceptsK_NAME | K_NEXT | K_VALUE | K_PUBLIC | K_STRING | K_DATAbut notK_TYPE)Tips:
data), which was fixed by [fix] Add 'K_DATA' to KeywordOrIdentifier to allow usages of 'data' as an identifier #2340 addingK_DATAtoKeywordOrIdentifier(). AddingK_TYPEthe same way fixes this case — I will raise a PR shortly.DROP COLUMNposition on master:comment,action,position,format,domain(and the datatype-token familytext,date,year,timestamp, which probably needs a different approach).