sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Not able to parser WHERE as a keyword

Open anupash147 opened this issue 7 years ago • 1 comments

Hello,

I have a simple test where I am trying to parser all keywords before i use this tool. Below is the code

s=select * from abc.xyz WHERE a='10' and B=20 or c=100 or D in ('10','20') order by id
p = sqlparse.parse(s)[0]
for token in p.tokens:
    print("{0} <== {1}".format(token.ttype,token.value))

i get the output as list of statements Token.Keyword.DML <== select Token.Text.Whitespace <==
Token.Wildcard <== * Token.Text.Whitespace <==
Token.Keyword <== from Token.Text.Whitespace <==
None <== abc.xyz Token.Text.Whitespace <==
None <== WHERE a='10' and B=20 or c=100 or D in ('10','20') Token.Keyword <== order Token.Text.Whitespace <==
Token.Keyword <== by Token.Text.Whitespace <==
None <== id

Above the where should have been a key word but it is not getting identified, Thats the problem. I looked in the code of Tokens, the also Where is identified as Keyword. Something is strange going on. I am using python 2.7. Need some help here.

anupash147 avatar Jan 19 '19 21:01 anupash147

Have you seen p._pprint_tree()? This give a much better look on the internal structure. But please keep in mind, that this internal structure may change at any time.

andialbrecht avatar Mar 11 '19 11:03 andialbrecht