If anyone's keen on the SQL parsing/transformation idea (presumably
for future, not now) there are some useful python tools with SQL
grammar at
https://web.archive.org/web/20020209211730/http://www.chordate.com/kwParsing/index.html
(included with gadfly).