sqlparse
sqlparse copied to clipboard
Single quoted literal with alias generates wrong tokens
Using version 0.3.0
In a query such as this:
SELECT 'fixed_text' ALIAS1 FROM .......
The tokens generated are: Token (ttype=Token.Literal.String.Single) = 'fixed_text' Identifier = ALIAS1
The expected tokens are: 1 Identifier with tokens containing a Single and an Identifier
Expected tokens are generated correctly when the 'AS' keword is used:
SELECT 'fixed_text' AS ALIAS1 FROM .......
If there are many fields in the select list, the behavior remains, but Identifier or IdentifierList tokens are generated before and/or after the Single:
SELECT 'fixed_text' ALIAS1, field1, field2 FROM .......
Will generate 1 Single and 1 IdentifierList, the IdentifierList will contain 3 Identifiers (ALIAS1, field1 and field2)
SELECT field1, field2, 'fixed_text' ALIAS1 FROM .......
Will generate 1 IdentifierList (field1, field2, 1 Single), 1 Identifier (ALIAS1)
same as
SELECT NULL ALIAS1, field1, field2 FROM .......
for oracle
i made it by adding "T.String.Single" to "ttypes" of "grouping.py::group_identifier()", but no further test.
i made it by adding "T.String.Single" to "ttypes" of "grouping.py::group_identifier()", but no further test.
i did this too, but it will take some Literal words in select (such as select "a" ...) into Identifier instead of Literal token, which seems reasonable.