Skip to content

Support for MERGE queries? #383

@olepbr

Description

@olepbr

Salut Gilles,

Thank you for a great tool. I tried to format a MERGE query using pgFormattter today, and noticed that the result could be improved. To see this, consider the last example on the PostgreSQL documentation's MERGE page:

MERGE INTO wines w
USING new_wine_list s
ON s.winename = w.winename
WHEN NOT MATCHED BY TARGET THEN
  INSERT VALUES(s.winename, s.stock)
WHEN MATCHED AND w.stock != s.stock THEN
  UPDATE SET stock = s.stock
WHEN NOT MATCHED BY SOURCE THEN
  DELETE;

When fed through pgFormatter, we get this:

MERGE INTO wines w
USING new_wine_list s ON s.winename = w.winename
WHEN NOT MATCHED BY
        TARGET THEN
        INSERT
            VALUES (s.winename, s.stock)
            WHEN MATCHED
                AND w.stock != s.stock THEN
                UPDATE SET
                    stock = s.stock
            WHEN NOT MATCHED BY
                    SOURCE THEN
                    DELETE;

Now, there are multiple things one could change here, but I think at the very least each WHEN clause should be on a single line and have the same indentation (as in the PostgreSQL docs), and the INSERT, UPDATE and DELETE keywords should have the same indentation (also as in the PostgreSQL docs).

I would be happy to try to contribute a patch for this, but I must admit I have yet to look at the codebase (beyond grepping for MERGE and seeing that there are no tests for it) :-)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions