Starting points for your own code. Run them in the environment shown below.
Node.js 22+ · ES module (.mjs)
Current inputs apply only to fields used by the example. Selected files are not embedded.
Install dependencies
npm install sql-formatter
import { format } from "sql-formatter";
const sql = "select id,name from users where active=true order by id";
console.log(format(sql, { language: "postgresql", keywordCase: "upper", tabWidth: 2 }));
// Formatting only; this code does not connect to a database or execute SQL.
Put it to work
Format readable SQL for your selected dialect.
Details that matter
Format and meaning
Does not execute queries. Formatting preserves comments and strings; it does not replace SQL validation.
Supported scope and limits
SQL 100 KB
Split inputs that exceed the limit. If a format or algorithm is unsupported, choose a tool that matches your requirements instead of silently changing the format.