Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9279345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:36:40+00:00 2026-06-18T17:36:40+00:00

I need to ‘pretty print’ a mysql query. The query is very long and

  • 0

I need to ‘pretty print’ a mysql query. The query is very long and complex and doing this in code is cumbersome. The language doesn’t matter too much, but I am writing a web app so javascript ( to do it client side ) or ruby ( server side ) would be ideal.

Are there any libraries out there that will do this for me?

I imagine it would do something like this…

   s = "select foo, bar from baz join bif on baz.id = bif.id where bar = 10"

   f= format( s ) # this would return something like the following.

   f = "SELECT
         foo,
         bar
       FROM baz
       JOIN bif
       ON baz.id = bif.id
       WHERE bar = 10"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:36:41+00:00Added an answer on June 18, 2026 at 5:36 pm

    I solved this using the sqlformat web service that appspot offers. I could have written my own web service using the above Sql Beautify method, but I did not want to introduce a new language into our code repository ( we only use ruby, python, and javascript ).

    # Hits the following web-service
    # http://sqlformat.appspot.com/format/
    
    # Github page
    # https://github.com/andialbrecht/sqlparse/
    
    # Documentation
    # http://sqlformat.appspot.com/api/
    # data - The SQL statement to format.
    # remove_comments - Set to 1 to remove comments.
    # keyword_case - How to convert keywords. Allowed values are 'lower', 'upper', 'capitalize'.
    # identifier_case - How to convert identifiers. Allowed values are 'lower', 'upper', 'capitalize'.
    #  - while this is an option I found it capitalizes table names which breaks the query. BE CAREFUL
    # n_indents - An integer indicating the indendation depth.
    # right_margin - An integer indicating the maximum line length.
    # output_format - Transfer the statement into another programming language. Allowed values are 'python', 'php'
    
    # {
    #   :data => query,
    #   :format => 'text',
    #   :remove_comments => 1,
    #   :keyword_case => 'upper',
    #   :n_indents => 2,
    # }
    
    # or, just pass in a the query as a string and the above params will be the default
    
    def DB::format_sql( params )
        if( params.class == String )
            params = {
                :data => params,
                :format => 'text',
                :remove_comments => 1,
                :keyword_case => 'upper',
                :n_indents => 2,
            }
        end
    
        res = Net::HTTP.post_form(URI.parse('http://sqlformat.appspot.com/format/'), params )
        return res.body
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need just a push in the right direction with this. I'm building a multi-language
need help on this one: here's a my sample code, i would like to
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need some regular expressions help. So far I have my code working to allow
Need help with a query that I wrote: I have three tables Company id
Need to write an SQL Query To get any 2 EmpCode for every EmpGroup
Need some help with Python syntax Pesudo code if param is not None in
Need some help with a SQL query. I have three tables TestOptions, CreateScript and
Need to launch a new ASP.NET site on this server but need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.