SQL Pretty Printer

Format SQL for SQLite, Postgres, MySQL and standard SQL.

SQL Pretty Printer— runs in your browser
0 chars

How to use it

  1. Paste a query into Input, or press Load sample.
  2. Choose the SQL dialect, tab width, keyword case and indent style. The result updates as you type.
  3. Copy the formatted query or download it as a .sql file.

About

Queries copied out of logs, ORMs or old scripts tend to be one long line, or indented in whatever style the last person liked. This lays them out consistently so they’re easier to read, review and diff.

Formatting uses the open source sql-formatter library, served from this site. Pick the dialect you’re writing for: it changes which keywords and operators the formatter recognises, so PostgreSQL’s :: casts or MySQL’s backtick quoting come out right.

Tabular indent styles line keywords up in a column, which some teams prefer for long SELECT lists. Your query isn’t uploaded anywhere.

Questions

Does it check my SQL is valid?

No. It formats the query’s layout but doesn’t run it or check it against a schema. If the formatter can’t make sense of the input, it shows an error instead.

Which dialect should I pick?

The database you’ll run the query on. Standard SQL works for most simple queries.

Will it change what my query does?

No. Only whitespace and, if you choose, keyword case change.