r/Python•
exeter

Help, python.reddit! Seeking a SQL parser

I'm looking for a SQL parser I can use from Python that will give me a parse tree to work with. Ideally, I'd do something like

parse_tree = parser.parse (sql)

and have a nice syntax tree I can walk. I'd like to support a large subset of ANSI SQL, but, at a minimum, I'd like to be able to support CREATE, UPDATE, DROP, SELECT (with WHERE clauses), and INSERT.

Thanks for any help!

Posted Aug 11, 2009, 9:00 AM UTC

43
mitsuhiko•

There you go: http://code.google.com/p/python-sqlparse/

Next time ask on stackoverflow :)

6
clesch•
5
rz2000•

I really enjoy googling something, and finding that the first results are all "rtfm", look it up, search the forum, etc. LMGTFY is a clever answer to a private question, but posting it as a public answer makes Google less efficient.

0
digitallogic•

You might want to check out the example that comes with pyparsing: http://pyparsing.wikispaces.com/file/view/simpleSQL.py

3