Splitting sql queries not separated by semicolons

82 views
Skip to first unread message

Thomas Seaford

unread,
Jan 19, 2017, 6:09:11 PM1/19/17
to sqlparse
I am using sqlparse to analyze some queries from 100+ SSRS reports. There are situations where a single dataset will contain multiple queries. One example would be when using a temp table; there could be a SELECT INTO #temp followed by another SELECT statement. In these cases, if the first query does not terminate with a semicolon then sqlparse appears to group the WHERE from the first query and all remaining sql together.


Instead of









The best answer would be to write more precise SQL. Unfortunately, since I am using sqlparse to do analysis on other people's work, I need to find a way to account for this. I have tried splitting the queries before parsing, but split() appears to rely on the ';' as well. This looks like it takes place in StatementFilter.Process().

Is this a bug, or expected behavior? I would appreciate any suggestions.



Andi Albrecht

unread,
Jan 24, 2017, 5:56:37 AM1/24/17
to sqlparse
Hi,

this is the expected behavior. sqlparse does it's best to analyze even broken queries. But without a semicolon it has no clue when a statement ends and another one begins. 

The reason behind this, is that one of the use cases for sqlparse is the usage in editing environments where the queries are "broken" (in progress, in development) 90% of the time.

Best regards,

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