sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

#comments without space after # ,get_type() is UNKNOWN

Open yangjiuyi opened this issue 6 years ago • 3 comments

HI!


sql = """#comments
select * from test_user WHERE id= 1;"""
sql1 = sqlparse.parse(sql)
t = sqlparse.sql.Statement(sql1[0].tokens)
sql2 = sqlparse.format(sql,strip_comments=True)

print t.get_type()
print sql2

sqltest =  """# comments
select * from test_user WHERE id= 1;"""
sqltest1 = sqlparse.parse(sqltest)
t1 = sqlparse.sql.Statement(sqltest1[0].tokens)
sqltest2 = sqlparse.format(sqltest,strip_comments=True)

print t1.get_type()
print sqltest2


output

UNKNOWN

#comments
select * from test_user WHERE id= 1;
----------
SELECT
select * from test_user WHERE id= 1;



MySQL support #comments without space after # sqlparse cannt support #comments without space after #?

yangjiuyi avatar Nov 07 '19 08:11 yangjiuyi

Do we have any update on this issue, comments are not stripped and the query does not split as well when #<not_space comments> are encountered

udit19524 avatar Dec 10 '20 18:12 udit19524

example:

import sqlparse sql = """#comments1 select id from test_user; select id from test_user2; """ query_list = sqlparse.split(sql) print(query_list) ['#comments1\nselect id\nfrom test_user;\nselect id\nfrom test_user2;']

import sqlparse sql = """# comments1 select id from test_user; select id from test_user2; """ query_list = sqlparse.split(sql) print(query_list)

result: ['# comments1\nselect id\nfrom test_user;', 'select id\nfrom test_user2;']

No space after # and a backtick is not working in harmony to split the sql queries

udit19524 avatar Dec 10 '20 20:12 udit19524

See #596 as well

andialbrecht avatar Dec 30 '22 08:12 andialbrecht