Redshift Formatter
Format Amazon Redshift SQL with Redshift rules for strings with backslash escapes, double-quoted identifiers, #temp tables, :: casts and $$ function bodies. QUALIFY and MINUS are kept as clauses, MERGE branches start new lines and long column lists are placed one per line. Unclosed strings and parentheses are reported with line and column, which helps analysts and data engineers review warehouse code.
Frequently asked questions
Which Redshift syntax is understood?
Single-quoted strings with backslash escapes and doubled quotes, double-quoted identifiers, #temp table names and :: casts are recognized. The regular expression operators ~ and ~* with their negated forms and $$ dollar-quoted function bodies are kept intact.
How does this differ from the PostgreSQL Formatter?
Redshift started from PostgreSQL but differs: backslashes escape characters in its strings, # starts a temporary table name instead of being an operator, and QUALIFY and MINUS are available. This formatter follows those rules.
What happens to UDF bodies?
Bodies of Python or SQL user defined functions written between $$ markers are kept exactly as written. Only the statement around them is formatted.
Which clauses get their own line?
SELECT, FROM, WHERE, GROUP BY, HAVING, QUALIFY, ORDER BY, LIMIT and OFFSET start their own lines. MINUS, UNION, INTERSECT and EXCEPT separate the queries they combine.
Does it support MERGE?
Yes. WHEN MATCHED and WHEN NOT MATCHED branches start new lines.
Are comments kept?
Yes. -- and /* */ comments stay in place. Multi-line block comments are re-indented to the new layout.
Does it change keyword case?
No. Keywords and names keep the case you wrote. Only whitespace and line breaks change.
Which errors are detected?
Unclosed strings, quoted identifiers, $$ bodies and block comments, and unbalanced parentheses, each with line and column. The SQL is not sent to your cluster.
How large can the input be?
Up to 1 MB per request and 128 KB per statement. Longer ETL scripts are formatted one statement at a time.
Can I choose the indentation, and is my SQL stored?
Use 2 or 4 spaces or tabs. The SQL is formatted in memory only and never saved.