Skip to content

Avoid newlines for SET statements #901

Open

Description

@chiawendt

Describe the Feature

Avoid newlines for SET statements.

Current:

SET
    statement_timeout = 0;
SET
    lock_timeout = 0;
SET
    idle_in_transaction_session_timeout = 0;
SET
    transaction_timeout = 0;
SET
    client_encoding = 'UTF8';
SET
    standard_conforming_strings = on;

Wanted:

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;

Why do you want this feature?
Denser format.

Activity

  1. nene commented on Sep 9, 2025

    @nene
    Collaborator

    Would be nice, yes. Unfortunately this happens because the formatter is unable to distinguish between SET in UPDATE ... SET and just plain SET. It does not understand context.

    So it's kinda unlikely to get fixed.

  2. added and removed on Sep 14, 2025
  3. changed the title [-]Feature Request: avoid newlines for SET statements[/-] [+]Avoid newlines for SET statements[/+] on Sep 14, 2025
  4. KJlt77 commented on Dec 3, 2025

    @KJlt77

    The same issue is with MySQL DEFAULT CHARACTER SET:

    CREATE DATABASE test DEFAULT CHARACTER
    SET
        utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    
    CREATE TABLE
        test.test (
            id bigint NOT NULL AUTO_INCREMENT,
            name varchar(255) DEFAULT NULL,
            PRIMARY KEY (id)
        ) ENGINE = InnoDB DEFAULT CHARACTER
    SET
        = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
    
  5. nene commented on Dec 3, 2025

    @nene
    Collaborator

    @KJlt77 you're either using an old version of sql-formatter or are not setting the dialect to MySQL. For me the above gets formatted as follows:

    CREATE DATABASE test DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    
    CREATE TABLE test.test (
      id bigint NOT NULL AUTO_INCREMENT,
      name varchar(255) DEFAULT NULL,
      PRIMARY KEY (id)
    ) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

    You can try it in here

  6. jansg08 commented on Jan 6, 2026

    @jansg08

    Same issue with DROP in the context of ALTER COLUMN column_name DROP NOT NULL. Presumably it's bugged for the same reason as SET as it assumes it's being used in the context of something like DROP TABLE table_name. If this does ever get fixed, could it be done so for DROP as well?

  7. KJlt77 commented on Jan 9, 2026

    @KJlt77

    @KJlt77 you're either using an old version of sql-formatter or are not setting the dialect to MySQL. For me the above gets formatted as follows:

    @nene I'm using SQL Formatter as an VSCode extension so it may be the issue with sql-formatter-vscode repo. I'm working with different SQL dialects so changing settings every time I open a different file is not an option.

    Extension has a dialect's auto-detect and statements I provided have keywords specific to MySQL, like DEFAULT CHARACTER SET % COLLATE %, ENGINE = InnoDB, so it would be nice if the file would be detected as MySQL.

    Setting/switching dialect with a comment in the file would be helpful too, though I failed to find such option.

    Either way, thank you for your contribution to this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions