Universal SQL Prettier
Features
Demo
How it looksBefore
After
Subquery — stays intact
UsageFormat a single selection
Format multiple separate queries
Format a block with several queriesSelect a block containing multiple statements separated by Format an entire
|
| Context | Example |
|---|---|
| Backtick template literal | const q = `SELECT * FROM users` |
| Double-quoted string | query = "SELECT * FROM users" |
| Single-quoted string | query = 'SELECT * FROM users' |
Raw .sql file |
entire file formatted on Shift+Alt+F |
| Plain selected text | select any SQL and press Ctrl+Alt+P |
Commands
| Command | Shortcut | Description |
|---|---|---|
| SQL: Format Query | Ctrl+Alt+P / Cmd+Alt+P |
Format selection, multiple selections, or whole file |
Configuration
{
"sqlFormatter.dialect": "postgresql",
"sqlFormatter.formatOnSave": false,
"sqlFormatter.keywordCase": "upper"
}
| Setting | Type | Default | Options | Description |
|---|---|---|---|---|
dialect |
string | "postgresql" |
postgresql mysql sqlite tsql |
SQL dialect |
formatOnSave |
boolean | false |
— | Auto-format SQL blocks on save |
keywordCase |
string | "upper" |
upper lower preserve |
Case applied to SQL keywords |
FAQ
My SQL isn't being formatted.
Make sure the selected text contains a recognisable SQL statement (SELECT … FROM, INSERT INTO, UPDATE … SET, DELETE FROM, or CREATE TABLE). If it doesn't match, a warning is shown.
Subqueries are being exploded onto separate lines. Update to the latest version — subquery-aware formatting (paren-depth tracking) was added to prevent this.
Can I format SQL in Go / Python / Java files?
Yes. Select the SQL string (with or without the surrounding quotes/backticks) and press Ctrl+Alt+P.
Will Shift+Alt+F work on non-SQL files?
No — the built-in Format Document provider is registered for .sql files only. Use Ctrl+Alt+P for other file types.
I have multiple queries in one selection — will both be formatted?
Yes. Queries separated by ;, a blank line, or a new statement keyword at the top level are each formatted independently and joined back with a blank line between them.
License
MIT — see LICENSE
Issues & Requests
github.com/sagarr-singh/vs_code_universal_sql_formatter_ext/issues
