Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/transactsql/transactsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down
43 changes: 43 additions & 0 deletions test/transactsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down