Skip to content

Support for ON CONFLICT DO [NOTHING | UPDATE] Syntax Formatting #288

@xterao

Description

@xterao

This update adds formatting support for SQL statements that include the ON CONFLICT clause. The formatting rules are as follows:

Formatting Rules

ON CONFLICT :

No line break or indentation; always appears inline

ON CONSTRAINT (if present):

Placed on the same line as ON CONFLICT, immediately following it

DO:

Always starts on a new line

Any query that follows DO (e.g., UPDATE, NOTHING) is indented relative to DO

Option Keywords

  • COLLATE
  • WHERE

EXCLUDE is not a reserved word, so do not add it as a keyword.
https://www.postgresql.org/docs/current/sql-keywords-appendix.html

Example (Formatted Output)

INSERT INTO users
            (username
             , email)
     VALUES ('user'
             , '[email protected]')
ON CONFLICT(username) ON constraint 
DO UPDATE
      SET email = EXCLUDED.email
          , created_at = CURRENT_TIMESTAMP

Sub-issues

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions