Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing SQL Query into a DOM-like tree to enable automatic permutation?

I have a large and complicated sql view that I am attempting to debug. There is a record not showing in the view and I need to determine which clause or join is causing the record to now show up. At the moment I am doing this in a very manual way, removing clauses one at a time and running the query to see if the required row shows up.

I think that it would be great if I could do this programmatically because I end up diving into queries like this about once a fortnight.


Does anybody know if there is a way to parse an SQL query into a tree of objects (for example those in sqlalchemy.sql.expression) so I am able to permuate the tree and execute the results?

like image 742
Ben Page Avatar asked Mar 19 '12 18:03

Ben Page


1 Answers

If you don't already have the view defined in SQLAlchemy, I don't think it can help you.

You could try something like sqlparse which might get you some of the way there. You could permute it's output and execute the permutations as raw sql using SQLA.

like image 127
EoghanM Avatar answered Oct 06 '22 01:10

EoghanM