← Back to tool

Postgres · Casts · Indent

PostgreSQL Formatter

Updated: June 2026

PostgreSQL adds its own flavour to SQL: double-colon casts, double-quoted identifiers, rich CTEs and window functions. This formatter parses them properly, so your Postgres queries come out tidy instead of broken.

Format My PostgreSQL →

Free · No upload · Instant in the browser

Tuned for PostgreSQL

PostgreSQL is standards-friendly but adds several conveniences that trip up naive formatters. The most common is the :: cast operator, a Postgres shorthand for converting a value's type. If a formatter treats the two colons as separate punctuation it will insert spaces and turn created_at::date into something invalid. This tool recognises :: as a single operator and keeps casts glued together.

It also respects double-quoted identifiers, which Postgres uses to preserve case or allow reserved words as names, and it understands the analytical features Postgres users lean on heavily: common table expressions with WITH, window functions with OVER, and PARTITION BY.

A PostgreSQL example

with recent as (select id,amount,created_at::date as d from payments where created_at > now() - interval '30 days') select d,sum(amount) as total from recent group by d order by d;

formats to:

WITH recent AS (
  SELECT
    id,
    amount,
    created_at::date AS d
  FROM
    payments
  WHERE
    created_at > now() - interval '30 days'
)
SELECT
  d,
  sum(amount) AS total
FROM
  recent
GROUP BY
  d
ORDER BY
  d;

The CTE body is indented inside its parentheses, the ::date cast stays intact, and the outer query reads cleanly underneath.

Window functions stay readable

Analytical Postgres queries can grow dense fast, with ROW_NUMBER(), RANK() and friends layered over PARTITION BY windows. Formatting keeps the function call inline where it belongs while still breaking the surrounding clauses onto their own lines, so a window expression reads as one unit instead of dissolving into a fog of parentheses. Combined with consistent keyword casing, even a multi-window report query becomes something you can review with confidence.

Private by design

Postgres queries often encode real business logic — pricing rules, eligibility checks, reporting definitions — and the table names alone can reveal a lot about a system. That is a good reason not to paste them into a server-side formatter. This one does all of its work in your browser, so nothing is transmitted, nothing is stored, and the formatter keeps running even with your network turned off. Format freely, including against production schemas.

Frequently asked questions

Does it support PostgreSQL :: casts?

Yes. The :: cast operator is recognised as a single operator, so expressions like value::int format correctly without stray spaces breaking the cast.

Does it handle CTEs and window functions?

Yes. WITH clauses, OVER (...) windows and PARTITION BY are all understood and laid out clearly so even complex analytical queries stay readable.

Is the PostgreSQL formatter private?

Yes. It runs entirely in your browser with no upload, so queries against your Postgres schema never leave your device and work offline.