Skip to content

Preserve block indentation after CREATE statements - #416

Merged
darold merged 2 commits into
darold:masterfrom
arnodirlam:codex/fix-create-table-block-indentation
Sep 19, 2026
Merged

darold merged 2 commits into
darold:masterfrom
arnodirlam:codex/fix-create-table-block-indentation

Conversation

@arnodirlam

Copy link
Copy Markdown
Contributor

While formatting a PL/pgSQL block, I noticed that statements after CREATE TABLE lose their enclosing indentation. This also pulls ELSE and END IF out of the block.

Before (pg_format, default options):

DO $$
BEGIN
    IF TRUE THEN
        CREATE TABLE t (
            id int
        );
ELSE
    PERFORM
        1;
END IF;
END
$$;

After:

DO $$
BEGIN
    IF TRUE THEN
        CREATE TABLE t (
            id int
        );
    ELSE
        PERFORM
            1;
    END IF;
END
$$;

The existing plancache.sql expected output had the same problem with four INSERTs after a CREATE TABLE inside a function; those now retain their enclosing indentation too.

I added a focused case covering ELSIF, ELSE, and following statements. prove -l t/ and the larger SQL corpus (perl t/regress_test.pl) pass; formatting the new case twice also gives identical output.

Thanks for maintaining pgFormatter!

@darold
darold merged commit 325accf into darold:master Sep 19, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants