andialbrecht / sqlparse

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

Support for nested SQL queries #412

Open AsliRoy opened 6 years ago

AsliRoy commented 6 years ago

I was trying to get this running with nested select statements, so I was wondering if you have a work-around for that. My SQL statement was something like, SELECT sub.* FROM (SELECT * FROM tutorial.sf_crime_incidents_2014_01 WHERE day_of_week = 'Friday') sub WHERE sub.resolution = 'NONE'
Can this be made to work? Thanks for the time. Cheers!

andialbrecht commented 6 years ago

What do you want to achieve? From what I can see the statement parses fine:

>>> print(sqlparse.format(sql, reindent=True))  # where sql is your statement
SELECT sub.*
FROM
  (SELECT *
   FROM tutorial.sf_crime_incidents_2014_01
   WHERE day_of_week = 'Friday') sub
WHERE sub.resolution = 'NONE'
AsliRoy commented 6 years ago

@andialbrecht , thank you for replying. Is there any way that the parser can be made to distinguish between the two select statements. Say for example on the given input, can it , say, separate it into two strings, and store them separately? Obviously, the dependency of the first string on the substring is noted. I just want them as two different strings, after parsing.