sql-formatter-org / sql-formatter-org/sql-formatter

[FORMATTING] Inconsistent formatting of PostgreSQL CREATE POLICY commands

Open
#928 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.9k
Forks
456
Avg merge
3d 4h
Merged PRs (30d)
3

Description

Input data

Which SQL and options did you provide as input?

CREATE POLICY "Allow users to select their own records" ON public.user_achievements
  FOR SELECT
  TO authenticated
  USING (user_id = auth.uid());

CREATE POLICY "Allow users to insert their own records" ON public.user_achievements
  FOR INSERT
  TO authenticated
  WITH CHECK (user_id = auth.uid());

Actual Output

CREATE POLICY "Allow users to select their own records" ON public.user_achievements FOR
SELECT
  TO authenticated USING (user_id = auth.uid ());

CREATE POLICY "Allow users to insert their own records" ON public.user_achievements FOR INSERT TO authenticated
WITH
  CHECK (user_id = auth.uid ());

Those two similar statements are formatted differently for no apparent reason.

Usage

  • How are you calling / using the library? tested with the demo and prettier-plugin-sql
  • What SQL language(s) does this apply to? PostgreSQL
  • Which SQL Formatter version are you using? (The exact version number.) 15.7.0

Contributor guide

Open the 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.

Research direction

Reproduce both PostgreSQL CREATE POLICY statements in the demo and with prettier-plugin-sql, using the reported formatter version, then compare how their clauses are laid out. Trace the PostgreSQL formatting path responsible for CREATE POLICY and verify that similar statements receive consistent formatting without changing their meaning.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.