3 ms·
You were a bit too quick in dismissing sqlparse. I had the same initial reaction but it does actually build a tree, more or less, by grouping together tokens. I
by contravariant 4y ago
You were a bit too quick in dismissing sqlparse. I had the same initial reaction but it does actually build a tree, more or less, by grouping together tokens. It doesn't build a full syntax tree, though. For instance, it doesn't attempt to identify the FROM or JOINs from a select statement for instance, but it does make sure to group things such that a FROM keyword following a SELECT is part of the same SELECT statement. This makes it flexible but does leave you with slightly more work (though it worked well enough for my purposes).