Skip to content

[HOTFIX] - Implement better handling of LIMIT/OFFSET in MSSQL driver#45

Merged
joshmcrae merged 10 commits intomasterfrom
hotfix-issue-44
Nov 4, 2025
Merged

[HOTFIX] - Implement better handling of LIMIT/OFFSET in MSSQL driver#45
joshmcrae merged 10 commits intomasterfrom
hotfix-issue-44

Conversation

@joshmcrae
Copy link
Member

@joshmcrae joshmcrae commented Oct 20, 2025

This PR updates Table and Mssql with special behaviour for the MSSQL driver to address #44.

Problem

MSSQL has multiple ways of selecting a limited number of rows.

  • SELECT TOP n [columns] FROM... where OFFSET and ORDER BY can be omitted
  • OFFSET n FETCH NEXT r ROWS ONLY where both an offset and limit must be specified

The OFFSET clause can also be used without a limit, so long as an ORDER BY is specified.

Currently, queries that are generated where only a limit is specified break because an OFFSET clause isn't added.

Solution

The Table class adds a TOP n modifier to the selected columns list when only a limit is specified, without an offset. In cases where both an offset and limit are specified, the original behaviour remains with a no-op ORDER BY being added if missing.

alankoroma
alankoroma previously approved these changes Oct 21, 2025
@joshmcrae joshmcrae requested a review from alankoroma November 4, 2025 22:02
@joshmcrae joshmcrae merged commit 788ce87 into master Nov 4, 2025
10 checks passed
@joshmcrae joshmcrae deleted the hotfix-issue-44 branch November 4, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants