Skip to content

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

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

Open
LuciaCam opened this issue May 22, 2025 · 1 comment
Open

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

LuciaCam opened this issue May 22, 2025 · 1 comment

Comments

@LuciaCam
Copy link

LuciaCam commented May 22, 2025

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
@LuciaCam LuciaCam added the bug label May 22, 2025
@nene nene changed the title [FORMATTING] Issue Title Here TransactSQL WITH (NOLOCK) is formatted as WITH-clause. May 22, 2025
@nene nene changed the title TransactSQL WITH (NOLOCK) is formatted as WITH-clause. TransactSQL table WITH (NOLOCK) is formatted as WITH-clause. May 22, 2025
@nene
Copy link
Collaborator

nene commented May 22, 2025

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
Projects
None yet
Development

No branches or pull requests

2 participants