vertical-align may stop working with certain CHECK constraint expressions

Open
#412 0 comments 1 reaction 0 assignees View on GitHub

@dajiaohuang is already working on this.

Since Oct 16, 2026.

  • #423 by @dajiaohuang — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
postgresql, sql
Domain
databases, tooling

Research direction

Reproduce the problem with the supplied SQL on pgFormatter 5.11, comparing the CHECK constraint table with the following table. Trace the vertical-align formatting behavior around CHECK expressions; done when both tables and subsequent statements receive vertical alignment consistently, with coverage for the reported example.

Written by the indexing model from the issue text.

Description

Thank you for developing and maintaining such a useful tool.

The long-awaited vertical-align feature was added in the latest version: #398

However, although I have not been able to determine the exact conditions that trigger the issue, it seems that certain CHECK constraint expressions can cause vertical alignment not to be applied.

For example, with the following SQL, vertical alignment is not applied to sample_with_check. Once this happens, vertical alignment is also not applied to the SQL statements that follow it, such as sample_after_check.

This does not seem to occur with every CHECK constraint, so the issue may depend on the contents or structure of the constraint expression.

I am using pgFormatter version 5.11 on macOS.

CREATE TABLE sample_with_check
(
    id VARCHAR(36) NOT NULL,
    code SMALLINT NOT NULL,
    description VARCHAR(255),
    CONSTRAINT ck_code_description
        CHECK (code <> 4 OR (description IS NOT NULL AND description <> ''))
);

CREATE TABLE sample_after_check
(
    id SERIAL NOT NULL,
    description TEXT NOT NULL,
    PRIMARY KEY (id)
);
Dominant language
PLpgSQL
Stars
2k
Forks
124
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

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.

More from darold/pgFormatter

All issues in darold/pgFormatter

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.