Skip to content
OddsockLocal
Local
Source text
SQL dialectsql
ReadyRuns in this browser. Nothing is uploaded.

How to use

  1. Paste a statement.
  2. Choose SQL dialect. postgresql, mysql, sqlite, transactsql, bigquery or the generic sql.
  3. Read the indented statement. Keywords are uppercase.
  4. Check quoted text and identifiers. Their contents should match what you pasted.

What is SQL formatter?

The formatter breaks a query onto several lines and uppercases keywords. select id, name from users where active = true and name = 'a b' order by name, with the PostgreSQL dialect, becomes SELECT, a column list, FROM users, a WHERE clause with AND on its own line, and ORDER BY. The boolean becomes TRUE. The string 'a b' keeps the three spaces between a and b.

Read more

Dialect is the control that changes quoting and a few keyword spellings. The choices are sql, postgresql, mysql, sqlite, transactsql and bigquery. sql is the generic start. Pick the dialect that matches the engine you will run, especially if you use backticks, square brackets or dollar quotes. The formatter does not connect to a database and does not check that the tables exist.

The minifier is the reverse: one line, same keyword case, strings still untouched. If a quote is missing, both pages will follow the formatter’s parse, which may not be the query you thought you wrote.

Use cases

  • A query pasted from a log is one line and you want SELECT, FROM and WHERE on separate lines before a review.
  • active = true should read TRUE, and you want to confirm the dialect did that without eating the spaces in 'a b'.
  • A SQL Server query uses brackets and should be formatted as transactsql rather than as generic sql.
  • You are about to minify and you want a readable copy saved first.

A PostgreSQL select, keywords uppercased

Dialect postgresql. select id, name from users where active = true and name = 'a b' order by name

SELECT id, name FROM users WHERE active = TRUE AND name = 'a b' ORDER BY name, broken across lines. The three spaces inside the string stay.

Why use Oddsock

The string is the regression. A formatter that collapses 'a b' to 'a b' has changed the query.

Related tools

Using this tool

Keywords are uppercased, and in the PostgreSQL dialect true is a keyword. The string 'a b' is not a keyword, so its spaces stay.