darold / darold/pgFormatter

vertical-align may stop working with certain CHECK constraint expressions

Open
#412 0 comments 0 reactions 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

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)
);

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

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.