# PostgreSQL Formatter

Format PostgreSQL queries and scripts with Postgres rules for dollar-quoted function bodies, E'' escape strings, double-quoted identifiers, :: casts and JSON operators such as ->> and @>. Clauses like RETURNING, ON CONFLICT and DO UPDATE SET get their own lines, and unclosed strings, comments or parentheses are reported with line and column. Made for developers reading migrations and queries.

## Frequently asked questions

### Which PostgreSQL syntax is understood?

Standard strings with doubled quotes, E'' strings with backslash escapes, U&'' Unicode strings, B'' and X'' bit strings, double-quoted identifiers and $1 parameters are recognized. Dollar-quoted strings such as $$...$$ or $body$...$body$ are read as well.

### What happens to function bodies in dollar quotes?

A dollar-quoted body is kept exactly as written, because it is a string to PostgreSQL. The surrounding CREATE FUNCTION statement is formatted, the body itself is not changed.

### Are casts and operators kept intact?

Yes. Casts such as value::integer stay joined, and operators like ->, ->>, #>, #>>, @>, <@, ?|, ?&, @@ and the regular expression operators ~ and ~* with their negated forms are never split. In PostgreSQL # is an operator, not a comment.

### Which PostgreSQL clauses get their own line?

RETURNING, ON CONFLICT, DO UPDATE SET, FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE and FOR KEY SHARE are kept together as clauses. The usual SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT and OFFSET clauses start their own lines too.

### Are comments preserved?

Yes. Line comments and block comments stay in place, and nested block comments, which PostgreSQL allows, are read correctly. Multi-line block comments are re-indented to their new position.

### Does it support MERGE?

Yes. WHEN MATCHED and WHEN NOT MATCHED branches start new lines, so MERGE statements from PostgreSQL 15 and later stay readable.

### Does it change keyword case?

No. Keywords and identifiers keep the case you wrote. Quoted identifiers are case sensitive in PostgreSQL, and they are never touched.

### Which errors are detected?

Unclosed strings, quoted identifiers, dollar-quoted strings and block comments, and unbalanced parentheses are reported with line and column. The tool does not check the full PostgreSQL grammar or your schema.

### How large can the input be?

Up to 1 MB per request and 128 KB per statement. Migration files with many statements are formatted one statement at a time and separated by blank lines.

### Can I choose the indentation?

Yes. Use 2 or 4 spaces or tabs. Your SQL is processed in memory only and never stored.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad The agent-ready plugin suite for WordPress.](https://sleekwp.com/?ref=oneclickpro)
