Skip to content

[FORMATTING] PostgreSQL: MERGE (PostgreSQL 15+) is not recognized #986

Open

Description

@jemersonln5

PostgreSQL has supported MERGE since version 15, but the postgresql dialect does not seem to know the statement: merge, matched and insert stay lower case with keywordCase: 'upper', and the clauses are not laid out the way MERGE is in plsql, transactsql or bigquery.

Input data

merge into stock as t using incoming as s on t.sku = s.sku when matched then update set qty = s.qty when not matched then insert (sku, qty) values (s.sku, s.qty);

Expected Output (roughly what other dialects produce)

MERGE INTO
  stock AS t USING incoming AS s ON t.sku = s.sku
WHEN MATCHED THEN
UPDATE SET
  qty = s.qty
WHEN NOT MATCHED THEN
INSERT
  (sku, qty)
VALUES
  (s.sku, s.qty);

Actual Output

merge INTO stock AS t USING incoming AS s ON t.sku = s.sku WHEN matched THEN
UPDATE
SET
  qty = s.qty WHEN NOT matched THEN insert (sku, qty)
VALUES
  (s.sku, s.qty);

Reference: https://www.postgresql.org/docs/current/sql-merge.html

Usage

  • Calling format() from the npm package directly (Node.js), options { language: ..., keywordCase: 'upper' }.
  • SQL language(s): postgresql
  • SQL Formatter version: 15.9.0 (also reproduced on 15.6.12)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions