7

I'm looking for an easy tool which is helping to reformat SQL statements. So e.g.

SELECT foo, baa from baafoo where id > 10 and comment = 'John was it';

will become to something like

SELECT 
     foo, 
     baa 
FROM 
     baafoo 
WHERE 
     id > 10 
     and comment = 'John was it';

It's not about using a big tool like PowerDesigner or SQLWorkbench. Just a little straight forward one -- maybe command line based with reading from stdin and writing to stdout.

3

http://www.sql-format.com/ lets you format things with quite a lot of control if you can cope with a web interface rather than a command-line tool:

enter image description here

  • 1
    Looks good, but would like to have something offline. – frlan Jun 2 '14 at 18:12
  • Yup - we don't recommend web sites here (having said that, I upvoted this, as it useful for me to know ;-) – Mawg Dec 2 '15 at 13:57
3

I like the SQLBeautifier plugin for SublimeText. SublimeText is cross-platform (Windows, Linux, and OSX) and has a free trial with unlimited functionality. The plugin itself is free and open source (MIT Licensed). Installation is quite simple - just run installer for SublimeText, open SublimeText and install Package Control, then in Sublime Text type ctrl-shift-p and select Package Control:Install Packages then select SQLBeautifier.

I've used it and like i,t however it may not be quite what you're looking for so another good option is the back-end behind it; SQLParse python (2 or 3) library. The library is open sourced and free.

If you would prefer a web-app SQLParse is also hosted online. Or if you want an HTTP API that is available as well - free with a 500 requests/hr limit.

All of those will provide the same output (if given the same options that is ofc). It is slightly different than the one you showed:

SELECT FOO,
       BAA
FROM BAAFOO
WHERE ID > 10
  AND COMMENT = 'John was it';
  • Using Geany. Maybe possible to port as it's Python ... – frlan Jun 2 '14 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.