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

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

Open
#867 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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

Start by reproducing the issue with the provided TransactSQL input and default formatter settings, then trace how the TransactSQL dialect handles WITH and table hints. Done means WITH (NOLOCK) stays on the table reference, NOLOCK follows the configured uppercase keyword style, and the expected formatting is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
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.