// free tool

Redshift SQL formatter

Format Amazon Redshift SQL in your browser. Table definitions with distribution and sort keys, casts and window functions are laid out cleanly without changing what they do.

The formatter reads Redshift SQL with its PostgreSQL rules, plus the Redshift syntax listed below.

Drop a .sql file here to open it. It is read in your browser, not uploaded.

Formatted SQL
CREATE TABLE sales (
    sale_id BIGINT IDENTITY(1, 1),
    sold_at TIMESTAMP NOT NULL,
    region VARCHAR(32),
    amount DECIMAL(12, 2)
) DISTSTYLE KEY DISTKEY (region) COMPOUND SORTKEY(sold_at, region);
SELECT
    region,
    LISTAGG(DISTINCT rep, ', ') WITHIN GROUP (ORDER BY rep) AS reps,
    SUM(amount)::DECIMAL(14, 2) AS total
FROM
    sales
WHERE
    sold_at >= DATEADD(month, -3, GETDATE())
GROUP BY
    region;

Loading the formatter…

Shortcuts in the editor: Ctrl+Enter formats and Ctrl+Shift+Enter minifies (⌘ instead of Ctrl on a Mac). Your settings are remembered in this browser and kept in the page address, so a link shares your style – never your SQL.

What the formatter does with Redshift SQL

  • Table definitions lay out cleanly. A CREATE TABLE body gets one column per line, and DISTSTYLE, DISTKEY and COMPOUND or INTERLEAVED SORTKEY after it get your keyword casing.
  • Casts and functions. :: casts stay tight, and GETDATE(), DATEADD, IDENTITY(1, 1) and LISTAGG(…) WITHIN GROUP (ORDER BY …) are laid out like any other call.
  • PostgreSQL syntax works too: $1 parameters, $$ procedure bodies and Postgres operators are read the way Postgres reads them.

Good to know

  • Keyword casing covers standard SQL and PostgreSQL keywords, so Redshift-only words such as ENCODE keep the case you typed.

Examples

Redshift before and after

Before
create table sales (sale_id bigint identity(1,1), sold_at timestamp not null, region varchar(32), amount decimal(12,2)) diststyle key distkey (region) compound sortkey (sold_at, region);
select region, listagg(distinct rep, ', ') within group (order by rep) as reps, sum(amount)::decimal(14,2) as total from sales where sold_at >= dateadd(month, -3, getdate()) group by region;
After
CREATE TABLE sales (
    sale_id BIGINT IDENTITY(1, 1),
    sold_at TIMESTAMP NOT NULL,
    region VARCHAR(32),
    amount DECIMAL(12, 2)
) DISTSTYLE KEY DISTKEY (region) COMPOUND SORTKEY(sold_at, region);
SELECT
    region,
    LISTAGG(DISTINCT rep, ', ') WITHIN GROUP (ORDER BY rep) AS reps,
    SUM(amount)::DECIMAL(14, 2) AS total
FROM
    sales
WHERE
    sold_at >= DATEADD(month, -3, GETDATE())
GROUP BY
    region;

The output uses the Standard style with 4-space indents, exactly as the formatter above produces it. Switch the style to Compact for denser SQL or Expanded for leading commas and one item per line. The formatter docs cover the details.

Redshift formatter FAQ

How does the formatter read Redshift SQL?

With its PostgreSQL rules, since Redshift is based on PostgreSQL and shares its quoting, :: casts and $$ strings. Redshift table attributes such as DISTKEY and SORTKEY also get keyword casing.

Is my SQL sent to a server?

No. The formatter is compiled to WebAssembly and runs inside your browser tab. Your SQL is never uploaded, logged or stored, and once the page has loaded it keeps working offline.

Can formatting break my query?

It is built not to. After formatting, SQLly checks its output token by token against your input. If anything other than whitespace and the casing you asked for would change, it gives your SQL back exactly as you wrote it and tells you why. SQL that does not parse cleanly, such as an unterminated string, is also left untouched, with the line and column of the problem.

Can I share my formatting settings with my team?

Yes. Every setting, including the advanced ones, is kept in the page address after the # sign, so copying the address or pressing Copy settings link shares your exact style. The link holds the settings only, never your SQL.

// formatting is the least of it

Like the formatter? Meet the rest of SQLly

A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and this formatter built into the editor.