Skip to content

Formatting issue for DO $$ block #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
egel opened this issue Oct 29, 2021 · 3 comments
Closed

Formatting issue for DO $$ block #183

egel opened this issue Oct 29, 2021 · 3 comments
Labels
Milestone

Comments

@egel
Copy link

egel commented Oct 29, 2021

Hey, thanks for your attention upfront.

I recently wanted to try your formatter, which seems btw working very great and stable.
Unfortunately, I stumble upon a problem that my SQL code has been formatted in a way that stopped working while executing while doing migrations. Hope this might help you better structure your formatter. & keep being awesome :)

Code that works fine:

DO $$
  BEGIN IF NOT EXISTS (
    SELECT
      1
    FROM
      pg_type
    WHERE
      typname = 'translations_statuses'
  ) THEN CREATE TYPE translations_statuses AS ENUM (
    'todo',
    'in_progress',
    'to_verify',
    'to_accept',
    'rejected',
    'accepted'
  );
  END IF;
END $$;

Code after formatting which does not work:

DO $ $ BEGIN IF NOT EXISTS (
  SELECT
    1
  FROM
    pg_type
  WHERE
    typname = 'translations_statuses'
) THEN CREATE TYPE translations_statuses AS ENUM (
  'todo',
  'in_progress',
  'to_verify',
  'to_accept',
  'rejected',
  'accepted'
);

END IF;

END $ $;

sql-formatter version: v4.0.0

@inferrinizzard
Copy link
Collaborator

Hello, what language is this?

@eatonphil
Copy link

Hello, what language is this?

Looks like PL/pgSQL?

@nene
Copy link
Collaborator

nene commented May 3, 2022

This should now be fixed in latest master.

Everything between $$ ... $$ is now treated as a string and not touched by the formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants