sql-metadata
sql-metadata copied to clipboard
error detect with block for bracketed select statement with as for columns
sql_stat = """
with a as (select id, a from tbl1 ),
with b as (select id, b from tbl2)
(
select a.id, a.a + b.b as t
from a
left join b
on a.id=b.id
)
"""
tbls = Parser(sql_stat)
tbls.tables
get this result:
'NoneType' object has no attribute 'normalized'
I think the root cause is that the select statment is rounded with brackets and inside the select statement a columns use as keyword, this makes the Parser think it is a with block and the code if token.next_token.is_as_keyword in Parser.with_names get shot.
I'm getting the same for this case:
Parser("""
select * from (
with dummy + 1 as dummyPlusOne
select dummy, dummyPlusOne from system.one
)
""").tables
It throws
File "/home/vitalijus/.pyenv/versions/3.9.6/envs/python-apps/lib/python3.9/site-packages/sql_metadata/parser.py", line 344, in tables
with_names = self.with_names
File "/home/vitalijus/.pyenv/versions/3.9.6/envs/python-apps/lib/python3.9/site-packages/sql_metadata/parser.py", line 450, in with_names
token.next_token_not_comment.normalized
AttributeError: 'NoneType' object has no attribute 'normalized'