SQL-Formatter & Minifier – Complete Documentation, Best Practices & Integrations
The Zerlo SQL-Formatter & Minifier makes SQL immediately readable (Beautify) or compact (Minify). You control Indent (2/4/8 Spaces), Keyword-Case (UPPER/lower/Preserve) and in the Advanced section Comment-Strip as well as Enforce semicolon. Via Quick Access there are sample snippets ready, and with Self-Test you test the behavior in seconds. The page is accessible here: zerlo.net/formattersql.
Content
- Quick Start
- Functions at a glance
- Quick-access examples (Use cases)
- Advanced Options (Details & Pitfalls)
- Typical application categories (12 scenarios)
- Integration: Website, iFrame, Teams
- Optional JSON API (with examples)
- Self-Test (Step by Step)
- Pro tips, Performance & Security
- Dialect hints & limitations
- Troubleshooting & FAQ
- Try it now
1) Quick Start
- Open zerlo.net/formattersql.
- Paste your SQL on the left or type it.
- Select the Mode: Beautify (readable) or Minify (compact).
- Set Indent (2/4/8) and Keyword-Case (UPPER/lower/Preserve) on..
- Optional: Remove comments, Enforce semicolon.
- Click Format – – the result appears on the right, including Copy and Save as .sql.
- Under Self-Test you can automatically test the core rules..
2) Features at a glance
- Beautify:: Breaks & indentation for
SELECT,FROM,JOIN,WHERE,GROUP BY,HAVING,ORDER BY,LIMIT,UNION,WITH,CASE… - Minify:: Removes unnecessary whitespaces; ideal for transport/embedding. Optional with comment-strip.
- Keyword-Case:: UPPER, lower or Preserve (Strings/Identifiers remain unchanged).
- Indent-Profile:: 2, 4 or 8 Spaces – team-wide consistent..
- Advanced:: Remove comments (single-/multi-line) & Enforce semicolon.
- Quick Access:: Preset examples: simple
SELECT, JOIN with aggregate, CASE & Subquery, CTE + Window, INSERT … RETURNING, UPDATE with CASE, DELETE + EXISTS. - Self-Test:: 1-Klick-Verifikation: Beautify rules, Minify behavior, Indent switching, Keyword-Case, Semicolon.
- Practical Buttons:: Format, JSON API (POST) test here, Copy, Save as .sql.
- Outputs:: Result pane, Self-Test, -Pane,.
3) Quick Access Examples (Use-Cases)
These examples cover the most common patterns and are ideal as a starting point.
SELECT id, name FROM products WHERE status = 'active';
SELECT c.id, c.title, COUNT(p.id) AS products
FROM categories c
LEFT JOIN products p ON p.category_id = c.id
GROUP BY c.id, c.title
ORDER BY products DESC;
SELECT u.id, u.email,
CASE
WHEN o.total >= 1000 THEN 'gold'
WHEN o.total >= 200 THEN 'silver'
ELSE 'bronze'
END AS tier
FROM users u
LEFT JOIN LATERAL (
SELECT SUM(total) AS total
FROM orders
WHERE user_id = u.id
) o ON TRUE;
WITH ranked AS (
SELECT id, customer_id, total,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY total DESC) AS rn
FROM orders
)
SELECT * FROM ranked WHERE rn = 1;
INSERT INTO users(email, role)
VALUES ('[email protected]', 'editor')
RETURNING id, email;
UPDATE accounts
SET status = CASE
WHEN balance < 0 THEN 'overdue'
WHEN balance = 0 THEN 'zero'
ELSE 'ok'
END
WHERE active = 1;
DELETE FROM sessions s
WHERE EXISTS (
SELECT 1 FROM users u
WHERE u.id = s.user_id AND u.deleted_at IS NOT NULL
);
4) Advanced Options (Details & Pitfalls)
- Remove comments:: Removes
-- ...and/* ... */. Good for clean transport (CI, embedding). Note: documentation comments are lost – consider extracting/archiving beforehand. - Enforce semicolon:: Adds
;if none at the end – prevents parser errors in scripts. If already;exists, nothing is duplicated.
5) Typical application categories (12 scenarios)
- Code Reviews:: Consistent layout speeds up reviews and prevents style discussions.
- Debugging:: Complex
JOIN/CASEbecome immediately visually readable. - Knowledge sharing:: Readable SQL for Wiki/Confluence/README.
- Migrations & Scripts:: Semicolon safety, unambiguous blocks.
- API Embedding:: Minify + Comment-Strip to embed SQL in apps/services.
- BI/Reporting:: Clean queries from BI tools before sharing.
- Learning & Training:: CTEs/Window functions shown in a structured way.
- Refactoring:: First beautify, then isolate/optimize sections.
- Bug reproduction:: Clearly structured queries for support tickets.
- Style-guide enforcement:: Team standard (Indent/Case) consistently applied.
- Templates:: „Quick Access“ as the basis for new queries.
- Release readiness:: Minify for stable, portable artifacts..
6) Integration into Website/Teams
A) Use directly
Here’s the tool: zerlo.net/formattersql
B) iFrame embedding (Intranet/Backoffice)
<iframe src="https://zerlo.net/formattersql" title="SQL Formatter" width="100%" height="900" style="border:0; border-radius:12px;"></iframe>
C) Team Style Guide (Base)
- Indent: 2 or 4 spaces (throughout).
- Keyword-Case: UPPER (Strings/Identifiers remain unchanged).
- JOINs: conditions directly on
JOIN ... ON; no hidden filters inWHERE. - CASE: CASE: Each
WHEN/THENin its own line; meaningful; meaningfulELSE. - Semicolon: Always set in scripts.
7) Optional JSON API
You can automate formatting in tools/CI/CD. A concise example:
POST https://zerlo.net/formattersql?api=1
Content-Type: application/json
{
"sql": "select id,name from users where id=1",
"mode": "beautify",
"options": { "indent": 4, "keywordCase": "upper", "stripComments": false, "ensureSemicolon": true }
}
{
"ok": true,
"result": "SELECT id, name\nFROM users\nWHERE id = 1;",
"stats": { "ms": 4, "inLen": 43, "outLen": 47 }
}
// Node.js (fetch)
const res = await fetch("https://zerlo.net/formattersql?api=1", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
sql: "SELECT * FROM orders WHERE created_at >= NOW() - INTERVAL '7 days';",
mode: "beautify",
options: { indent: 2, keywordCase: "upper", stripComments: true, ensureSemicolon: true }
})
});
const data = await res.json();
console.log(data.result);
<?php
// PHP
$payload = [
"sql" => "SELECT COUNT(*) FROM products;",
"mode" => "minify",
"options" => [ "indent" => 2, "keywordCase" => "preserve", "stripComments" => true, "ensureSemicolon" => true ]
];
$ch = curl_init("https://zerlo.net/formattersql?api=1");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true
]);
$resp = curl_exec($ch);
curl_close($ch);
echo $resp;
8) Self-Test (Step by Step)
- Click in the tool below on Self-Test – – three core cases are automatically tested..
- Beautify Case:: Keywords UPPER, Keywords UPPER, clear breaks, clean indent.
- Minify Case:: Comments removed (if option active), compact output.
- Indent Case:: Visible switch between 2/4/8 spaces..
- Result appears in the Self-Test pane; if there are deviations: check options and possibly switch mode.
9) Pro Tips, Performance & Security
- Large scripts:: After 'Beautify', split into thematic blocks (CTEs, DDL vs DML), then version individually..
- Review Pace:: Use 'Quick Access' as the standard template; avoids bloat with new queries..
- Minimize error sources:: „Enforce semicolon“ Enable in migration pipelines..
- Strings remain unchanged:: The formatter does not edit contents in quotes; business logic remains safe..
- Privacy:: No SQL execution – plain text. Do not permanently store sensitive content in third-party tools..
- Comparisons made easier:: Beautify, then compare with Git-Diff – differences jump out at you..
10) Dialect Hints & Limits
- MySQL/MariaDB: Standard keywords & functions are recognized well..
- PostgreSQL/SQLite: CTEs/Window-Funktionen CTEs/Window functions are neatly indented;
RETURNINGit lends itself well.. - Exotics:: Very specialized dialect syntax (e.g., proprietary hints) remains content-wise; formatting is generic..
- No semantic analysis:: The formatter does not 'understand' logic – it structures text. Syntax errors remain syntax errors..
11) Troubleshooting & FAQ
„Nothing changes?“ – Check mode & options; input must not be empty.
„Double semicolons?“ – Enforce option + existing ;: disable the option.
„Comments were not removed“ – Enable comment-strip or switch mode to 'Minify'.
„Very long queries lag in the browser“ – Format large blocks sequentially or use the API.
„Keywords in strings changed?“ – Should not happen; check whether they were real strings (quotes, not backticks).
12) Now Try It
Start here: zerlo.net/formattersql