darold / darold/pgFormatter

indentation of FROM and WHERE in longer subquery doesn't match

Open
#243 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PLpgSQL
Stars
2k
Forks
121
Avg merge
4d 21h
Merged PRs (30d)
7

Description

Much like https://github.com/darold/pgFormatter/issues/240.

SELECT
    SELECT
        sum(amount)
    FROM
        payments + /* keep this comment to avoid crash */ (
            SELECT
                sum(amount)
            FROM payments
            WHERE
                owner_id IN (
                    SELECT
                        id
                    FROM invoices)) + coalesce((
            SELECT
                sum(amount)
            FROM payments
        WHERE
            TYPE IN ('xxx')), 0);
$ pg_format -v
pg_format version 5.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the formatting issue with pg_format version 5.0 using the SQL example in the report, then inspect the formatter's handling of nested subqueries and their FROM and WHERE clauses. Done means the longer subquery is consistently indented without the reported mismatch, while preserving the comment and valid SQL output.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, sql
Domain
databases, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.