From fdacc9d904e510c874d7e09c61837653ae44a442 Mon Sep 17 00:00:00 2001 From: zzoraemon043 <195147269+zzoraemon043@users.noreply.github.com> Date: Mon, 19 Oct 2026 09:53:22 +0800 Subject: [PATCH] Treat WITH TIES as a keyword phrase in Transact-SQL Fixes #984 --- .../transactsql/transactsql.formatter.ts | 1 + test/transactsql.test.ts | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/languages/transactsql/transactsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts index 01f6806cc7..bc4746ec2c 100644 --- a/src/languages/transactsql/transactsql.formatter.ts +++ b/src/languages/transactsql/transactsql.formatter.ts @@ -229,6 +229,7 @@ const reservedJoins = expandPhrases([ const reservedKeywordPhrases = expandPhrases([ 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE} BETWEEN', + 'WITH TIES', ]); const reservedDataTypePhrases = expandPhrases([]); diff --git a/test/transactsql.test.ts b/test/transactsql.test.ts index f3041c23fe..3540c01490 100644 --- a/test/transactsql.test.ts +++ b/test/transactsql.test.ts @@ -258,6 +258,49 @@ describe('TransactSqlFormatter', () => { `); }); + // Issue #984 + it('formats TOP ... WITH TIES', () => { + expect( + format('select top (3) with ties name, score from players order by score desc;', { + keywordCase: 'upper', + }) + ).toBe(dedent` + SELECT + TOP (3) WITH TIES name, + score + FROM + players + ORDER BY + score DESC; + `); + }); + + it('formats TOP ... PERCENT WITH TIES', () => { + expect( + format('select top (10) percent with ties name from players order by score desc;', { + keywordCase: 'upper', + }) + ).toBe(dedent` + SELECT + TOP (10) PERCENT WITH TIES name + FROM + players + ORDER BY + score DESC; + `); + }); + + it('formats TOP n WITH TIES without parentheses', () => { + expect(format('SELECT TOP 5 WITH TIES name FROM players ORDER BY score;')).toBe(dedent` + SELECT + TOP 5 WITH TIES name + FROM + players + ORDER BY + score; + `); + }); + // Issue #877 it('allows the use of the ODBC date format', () => { const result = format(