Skip to content

Commit 2b0de9b

Browse files
authored
Merge pull request #3 from tqrcisio/fix/mssql-top-clause-strips-spurious-limit
fix: strip spurious LIMIT when query already has TOP clause in MSSQL adapter
2 parents 6ec3286 + 1d22e81 commit 2b0de9b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

pkg/adapter/mssql/mssql.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,11 @@ func (m *MSSQLAdapter) adaptQueryForVersion(query string) string {
435435
// or is not a SELECT statement (INSERT/UPDATE/DELETE are left as-is).
436436
func convertLimitToTop(query string) string {
437437
if hasTopRe.MatchString(query) {
438-
return query // already has TOP — leave untouched
438+
// already has TOP — strip any spurious LIMIT appended by QueryModifier
439+
if m := limitClauseRe.FindStringSubmatch(query); m != nil {
440+
return strings.TrimSpace(m[1])
441+
}
442+
return query
439443
}
440444
m := limitClauseRe.FindStringSubmatch(query)
441445
if m == nil {

0 commit comments

Comments
 (0)