Skip to content

fix: format PostgreSQL CREATE POLICY commands consistently - #2

Draft
cnbei wants to merge 1 commit into
masterfrom
cursor/pg-create-policy-format-dfe8
Draft

fix: format PostgreSQL CREATE POLICY commands consistently#2
cnbei wants to merge 1 commit into
masterfrom
cursor/pg-create-policy-format-dfe8

Conversation

@cnbei

@cnbei cnbei commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Fixes sql-formatter-org#928

SELECT was tokenized as reservedSelect and WITH as a CTE clause, so two similar CREATE POLICY statements wrapped differently:

  • FOR SELECT split into FOR + a new SELECT clause
  • FOR INSERT ... WITH CHECK kept FOR INSERT together, then started a WITH clause

Detect FOR {SELECT | INSERT | DELETE} as reserved clauses (next to the existing FOR UPDATE locking clause) and WITH CHECK as a keyword phrase (like WITH ORDINALITY). FOR SELECT and FOR INSERT now use the same layout.

Upstream compare (please open the PR here):
https://github.com/sql-formatter-org/sql-formatter/compare/master...cnbei:sql-formatter:cursor/pg-create-policy-format-dfe8?expand=1

gh pr create --repo sql-formatter-org/sql-formatter --head cnbei:cursor/pg-create-policy-format-dfe8 failed with Resource not accessible by integration.

Tests

pnpm exec jest test/postgresql.test.ts --coverage=false — 462 passed.

Open in Web Open in Cursor 

Recognize FOR {SELECT|INSERT|DELETE} as clauses and WITH CHECK as a
keyword phrase so SELECT vs INSERT policies no longer wrap differently.

Co-authored-by: cnbei <baymy@foxmail.com>
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.

[FORMATTING] Inconsistent formatting of PostgreSQL CREATE POLICY commands

2 participants