sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

sqlparse.parse result incorrect in parsing mysql alias in select clause.

Open BlackWatchuser opened this issue 4 years ago • 0 comments

version: 0.4.1 here is my example:

select  `user` as id , name 'test', mo ttt from mysql.user

then i use sqlparse.parse(sql)[0], here is the printed tree:

 0 DML 'select'
 1 Whitespace ' '
 2 IdentifierList '`user`...'
 |  0 Identifier '`user`...'
 |  |  0 Name '`user`'
 |  |  1 Whitespace ' '
 |  |  2 Keyword 'as'
 |  |  3 Whitespace ' '
 |  |  4 Identifier 'id'
 |  |  |  0 Name 'id'
 |  1 Whitespace ' '
 |  2 Punctuation ','
 |  3 Whitespace ' '
 |  4 Identifier 'name'
 |  |  0 Name 'name'
 3 Whitespace ' '
 4 IdentifierList ''test'...'   # as you can see in here,   name 'test' should be parsed as one Identifier('test' is alias), but is split it into two item, and leaving 'test' as a Single token.
 |  0 Single "'test'"
 |  1 Punctuation ','
 |  2 Whitespace ' '
 |  3 Identifier 'mo ttt'
 |  |  0 Name 'mo'
 |  |  1 Whitespace ' '
 |  |  2 Identifier 'ttt'
 |  |  |  0 Name 'ttt'
 5 Whitespace ' '
 6 Keyword 'from'
 7 Whitespace ' '
 8 Identifier 'mysql....'
 |  0 Name 'mysql'
 |  1 Punctuation '.'
 |  2 Name 'user'
 9 Whitespace ' '

so, could i assume this is a bug? can any one tell me how to fix it ?

BlackWatchuser avatar Jun 09 '21 07:06 BlackWatchuser