split comment lines

49 views
Skip to first unread message

hanga...@gmail.com

unread,
Mar 26, 2019, 12:19:49 AM3/26/19
to sqlparse
--echo # Test for valid seconds properly separated by decimal point with fractions.
SELECT TIME
'110203.1';
SELECT TIME
'010203.12';
SELECT TIME
'010203.123';
SELECT TIME
'010203.1234';
SELECT TIME
'010203.12345';
SELECT TIME
'010203.123456';
SELECT TIME
'010203.1234567';


SELECT TIME
'01021.1';


--echo # Test for valid time literals in insert operation.
CREATE TABLE t
(key1 INT UNIQUE, col TIME(6));


I have some string like this, I need to split them.

but the for the  comment lines split didn't works

The result is like this:

--echo # Test for valid seconds properly separated by decimal point with fractions.; SELECT TIME '110203.1';
SELECT TIME '010203.12';
SELECT TIME '010203.123';
SELECT TIME '010203.1234';
SELECT TIME '010203.12345';
SELECT TIME '010203.123456';
SELECT TIME '010203.1234567';
SELECT TIME '01021.1';
--echo # Test for valid time literals in insert operation.; CREATE TABLE t(key1 INT UNIQUE, col TIME(6));


it's not expected, because the next line of sql statement was add to the comment line.

How can I make the split work with comment lines and sql statement lines?

Thanks,
Han, Gang

Andi Albrecht

unread,
Mar 30, 2019, 10:32:36 AM3/30/19
to sqlp...@googlegroups.com
It's a bit hard to distinguish where the comment belongs to: Is it a
comment for the preceding line, for the following line? Or just a
comment in between.

Did you try something like sqlparse.split(sqlparse.format(SQL,
strip_comments=True))?

Andi
> --
> You received this message because you are subscribed to the Google Groups "sqlparse" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlparse+u...@googlegroups.com.
> To post to this group, send email to sqlp...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlparse.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages