How to format SQL without uploading your queries
Pasting a production query into a random "SQL formatter" website is a habit most of us have, and a quiet risk. Queries contain table names, column names and sometimes literal values you'd rather not hand to a server you
Pasting a production query into a random "SQL formatter" website is a habit most of us have, and a quiet risk. Queries contain table names, column names and sometimes literal values you'd rather not hand to a server you can't inspect. Here's how to check whether a tool really stays local, and what to watch for by dialect.
Check a tool before you paste
Open your browser's DevTools, go to the Network tab, paste a query and run the formatter. If a request fires that includes your SQL in its payload, the tool sends it to a server. If nothing happens when you format, the work is happening in your tab.
Dialect gotchas
A formatter that parses the wrong dialect will either error out or format a query badly:
-
PostgreSQL:
::casts,ILIKE,RETURNING,LATERALjoins, and$$ ... $$dollar-quoted function bodies. -
MySQL / MariaDB: backtick identifiers and
LIMIT offset, count. Note thatDELIMITERis a client command, not SQL, so no formatter can parse it. -
SQL Server (T-SQL):
[bracketed]identifiers andTOP. -
BigQuery: backticked project and dataset paths, and
UNNEST.
If a valid query fails to format, check the selected dialect before editing the query.
A before and after
select o.status, count(*) as orders, sum(o.total) as revenue from orders o where o.created_at >= '2026-01-01' and o.status <> 'cancelled' group by o.status having sum(o.total) > 1000 order by revenue desc;
SELECT
o.status,
count(*) AS orders,
sum(o.total) AS revenue
FROM
orders o
WHERE
o.created_at >= '2026-01-01'
AND o.status <> 'cancelled'
GROUP BY
o.status
HAVING
sum(o.total) > 1000
ORDER BY
revenue DESC;
Only whitespace and keyword case change. Literals and operators are untouched.
What a validator can and can't tell you
A parser-based validator catches unbalanced parentheses, unterminated strings and stray operators. It can't know your schema, so a misspelled column still "parses." Read a green result as "this is readable SQL," not "this is correct."
A tool I built for this
I built OnlineSQL because I wanted a formatter that runs in the browser. It formats, beautifies, minifies, validates and diffs SQL, and converts between SQL, JSON and CSV. It has dedicated pages for PostgreSQL, MySQL and other dialects. If you find a query it handles badly, I'd like to see it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.