PostgreSQL Formatter

Paste a PostgreSQL query and get it laid out clause by clause — with PostgreSQL syntax handled correctly.

Input · drop a file

Output

PostgreSQL-specific syntax this formatter understands

  • :: type casts and $1 positional parameters stay intact
  • JSON operators ->, ->>, ? and @> are kept as single tokens
  • Dollar-quoted function bodies ($$ … $$) are not broken apart
  • RETURNING, ON CONFLICT … DO UPDATE and USING are laid out as clauses

Formatting changes only whitespace and keyword case. What the query does is unchanged. Need another database? The main SQL formatter has 11 dialects, and the SQL minifier squeezes a query onto one line.

Questions

Is this PostgreSQL formatter free and private?

Yes. It runs in your browser using the open-source sql-formatter library; your query is never uploaded.

Does it support PL/pgSQL functions?

The SQL around a function definition is formatted; the dollar-quoted body is kept exactly as written so nothing inside it breaks.

Does it check my query against my schema?

No — it understands the syntax, not your tables. A nicely formatted query can still reference a column that doesn’t exist.

Related tools