Nifty / Extensions / Data & formats

Nifty SQL

Format SQL in 20 dialects, including dbt and Jinja templates, with your team's settings.

code --install-extension nifty.nifty-sql

Works in VS Code, Cursor, Windsurf, VSCodium and in the browser on vscode.dev and github.dev. Free.

Try it without installing anything: SQL Formatter · PostgreSQL Formatter · MySQL Formatter

Features

PostgreSQL picked from the status bar, then a one-line report query formatted with Format Document

A one-line PostgreSQL report query formatted with the team's .sql-formatter.json, with the dialect in the status bar

A dbt model formatted for Snowflake: ref() calls and the is_incremental() block survive

SQL inside a Python string formatted in place, keeping its indentation and the %(days)s parameter

  • 20 dialects. Standard SQL, PostgreSQL, MySQL, MariaDB, SQL Server (T-SQL), Oracle PL/SQL, SQLite, Snowflake, BigQuery, Redshift, DuckDB, ClickHouse, Spark, Hive, Trino, Db2, Db2 for i, N1QL, SingleStoreDB and TiDB.
  • Just use Format Document. Nifty SQL plugs into VS Code's built-in Format Document, Format Selection and format on save for SQL files.
  • Format SQL anywhere. Select a query inside Python, TypeScript, Go or any other file and run Nifty SQL: Format SQL. The result keeps the indentation of the surrounding code, and query parameters such as %(name)s, ${id} and :name stay as they are.
  • dbt and Jinja friendly. {{ ref('orders') }}, {% if is_incremental() %} and {# comments #} survive formatting untouched, and block tags stay on their own lines.
  • One style for the whole team. Commit a .sql-formatter.json to your repo and everyone gets the same output. It is the same file the sql-formatter CLI reads, so CI can check formatting too. You get autocomplete and validation while editing it.
  • The right dialect automatically. The dialect comes from the file's language (e.g. files marked MySQL or PostgreSQL by your database extension), and is shown in the status bar (a language in .sql-formatter.json wins). Click it to set a dialect for the workspace.
  • Errors you can read. If the SQL can't be parsed you get one line saying where, not a wall of text.
  • Works in the browser on vscode.dev and github.dev.

Commands

Command What it does
Nifty SQL: Format SQL (Document or Selection) Format the selection, or the whole file if nothing is selected. Works in any language.
Nifty SQL: Format SQL with Dialect… Pick a dialect for a one-off format
Nifty SQL: Set SQL Dialect for Workspace… Save the dialect for this workspace (also available by clicking the status bar)

Nifty SQL is the default formatter for .sql files. To format on save, add this to your settings:

"[sql]": {
  "editor.formatOnSave": true
}

Team configuration: .sql-formatter.json

{
  "language": "postgresql",
  "keywordCase": "upper",
  "tabWidth": 4,
  "linesBetweenQueries": 2
}

Nifty SQL uses the nearest .sql-formatter.json above the file (within the workspace). Its values override your personal settings.

Settings

Setting Default What it does
nifty.sql.dialect auto Dialect, or auto to use the file's language
nifty.sql.keywordCase preserve preserve, upper or lower for keywords
nifty.sql.dataTypeCase preserve Case for data types
nifty.sql.functionCase preserve Case for function names
nifty.sql.identifierCase preserve Case for table and column names
nifty.sql.indentStyle standard standard, tabularLeft or tabularRight
nifty.sql.logicalOperatorNewline before Line break before or after AND / OR
nifty.sql.expressionWidth 50 Width at which parenthesised expressions are split
nifty.sql.linesBetweenQueries 1 Empty lines between statements
nifty.sql.denseOperators false a+b instead of a + b
nifty.sql.newlineBeforeSemicolon false Put the closing ; on its own line
nifty.sql.templating auto Jinja/dbt handling: auto, jinja or none
nifty.sql.useConfigFile true Read .sql-formatter.json
nifty.sql.showDialectInStatusBar true Show the dialect in the status bar

Indentation (spaces or tabs, and width) follows your editor settings unless .sql-formatter.json sets it.