Skip to content

TransactSQL table WITH (NOLOCK) is formatted as WITH-clause. #867

Open

Description

@LuciaCam

Which SQL and options did you provide as input?
I am using the SQL Formatter VSCode extention with default settings except for the three following:
"SQL-Formatter-VSCode.dialect": "transactsql",
"SQL-Formatter-VSCode.functionCase": "upper",
"SQL-Formatter-VSCode.keywordCase": "upper",

The TransactSQL dialect does not seem to handle WITH (NOLOCK) appropriately. I think it considers it as a WITH statement, and it does not uppercase nolock automatically. For example:

Input data

select *
from table1 with (nolock)
left join table2 with (nolock) on table2.id = table1.id

Expected Output

SELECT
    *
FROM
    table1 WITH (NOLOCK)
    LEFT JOIN table2 WITH (NOLOCK) ON table2.id = table1.id

Actual Output

SELECT
    *
FROM
    table1
WITH
    (nolock)
    LEFT JOIN table2
WITH
    (nolock) ON table2.id = table1.id

Usage

  • How are you calling / using the library?
    I am using the SQL Formatter VSCode extention.
  • What SQL language(s) does this apply to?
    TransactSQL
  • Which SQL Formatter version are you using?
    The extension is v4.2.0

Activity

  1. changed the title [-][FORMATTING] Issue Title Here[/-] [+]TransactSQL WITH (NOLOCK) is formatted as WITH-clause.[/+] on May 22, 2025
  2. changed the title [-]TransactSQL WITH (NOLOCK) is formatted as WITH-clause.[/-] [+]TransactSQL `table WITH (NOLOCK)` is formatted as WITH-clause.[/+] on May 22, 2025
  3. nene commented on May 22, 2025

    @nene
    Collaborator

    Thanks for reporting.

    You're right in your diagnosis that the formatter thinks that this is a WITH-clause. Unfortunately this problem is pretty tricky to solve with the current architecture of the formatter.

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