You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running the sql-metadata parser on a bunch of sqlserver queries. Its pretty common to start a sql server query with the database name -
use cool_db;
In the parser, this throws a not supported error because the parser is only looked at the first query from sqlparse.
Or, if I have a messy statement -
;
;
;
select a from b;
;
The tool is currently only setup for us to pass in select a from b;, but it would be nice it if could handle messier stuff.
What do you think about iterating through the parsed parts instead of grabbing part one?
I'm using a simple wrapper which removes leading whitespace and punctuation -
parsed=sqlparse.parse(query)
forparseinparsed:
count=0# remove blank line tokens from front of queryforx, tokeninenumerate(copy(parse.tokens)):
iftoken.ttype==sqlparse.tokens.Text.Whitespace.Newlineandcount==0:
parse.tokens.pop(x)
else:
count+=1ifparse.tokens[0].ttype!=sqlparse.tokens.Punctuation:
ifparse.tokens[0].value=='USE':
continuea=Parser(str(parse))
I guess this leads to another question! What if we are querying cool_db and joining to another_cool_db - how can we determine which tables/column belong to which db?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm running the sql-metadata parser on a bunch of sqlserver queries. Its pretty common to start a sql server query with the database name -
In the parser, this throws a
not supported
error because the parser is only looked at the first query fromsqlparse
.Or, if I have a messy statement -
The tool is currently only setup for us to pass in
select a from b;
, but it would be nice it if could handle messier stuff.What do you think about iterating through the parsed parts instead of grabbing part one?
I'm using a simple wrapper which removes leading whitespace and punctuation -
I guess this leads to another question! What if we are querying
cool_db
and joining toanother_cool_db
- how can we determine which tables/column belong to which db?Beta Was this translation helpful? Give feedback.
All reactions