andialbrecht / sqlparse

A non-validating SQL parser module for Python
BSD 3-Clause "New" or "Revised" License
3.76k stars 700 forks source link

Parsing two SQL statements using split , the result is incorrect #648

Closed ccaiy9 closed 3 years ago

ccaiy9 commented 3 years ago
>>> import sqlparse
>>> t_sql = """create table dmc_o2_test(
...     stuid number(38) primary key,
...     stuname varchar2(30) not null
... )
...
... select * from dmc_o2_test;"""
>>>
>>>
>>> sqlparse.split(t_sql)
['create table dmc_o2_test(\n\tstuid number(38) primary key,\n  \tstuname varchar2(30) not null\n)\n\nselect * from dmc_o2_test;']
>>>
>>> len(sqlparse.split(t_sql ))
1

t_sql is two SQL statements, and there is no semicolon at the end of the first SQL statement。 But the result is considered one statement。 Is this a bug? Or is there any good solutions?

andialbrecht commented 3 years ago

Not a bug. This works as intended. For splitting SQL statements the module relies on semicolons. Otherwise it would get very complicated to identify statements. This is due to the nature of the parser which has no grammar (it's non-validating).

ccaiy9 commented 3 years ago

Not a bug. This works as intended. For splitting SQL statements the module relies on semicolons. Otherwise it would get very complicated to identify statements. This is due to the nature of the parser which has no grammar (it's non-validating).

Well, How can I solve this problem that SQL statement without semicolon? Any good suggestions? THANKS !