PostgreSQL Formatter Online

Format PostgreSQL queries with dialect support for JSONB operators, casts and Postgres functions. Paste SQL, choose PostgreSQL and beautify.

Part of the free SQL Formatter. Runs in your browser — nothing is uploaded.

PostgreSQL Formatter Online

PostgreSQL adds syntax standard SQL formatters can mangle, such as the -> and ->> JSONB operators, @> containment and :: casts. Select the PostgreSQL dialect in the tool and those are formatted correctly.

Worked example: JSONB operators and a cast in PostgreSQL

Input

select id, data->>'name' as name, created_at::date as day from events where data @> '{"type":"signup"}' order by created_at desc limit 20;

Formatted PostgreSQL

SELECT
  id,
  data ->> 'name' AS name,
  created_at::date AS DAY
FROM
  events
WHERE
  data @> '{"type":"signup"}'
ORDER BY
  created_at DESC
LIMIT
  20;

Practical tip

Set the dialect to PostgreSQL before formatting. Using Standard SQL may add stray spaces inside operators like ->> or ::.

How to use this SQL Formatter

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

PostgreSQL Formatter Online FAQs

Does it support Postgres JSONB operators?

Yes. With the PostgreSQL dialect selected, operators like ->, ->>, #>, @> and the :: cast are kept intact.

Can I format a psql script with several statements?

Yes. Paste multiple statements separated by semicolons and each is formatted in turn.

More SQL Formatter pages

Open the full SQL Formatter tool →