Skip to content

Commit f59b59b

Browse files
Fix an issue of adding OFFSET keyword for legacy SQL Server vresions
I was getting the following exception when trying to access legacy SQL Server 2008 R2 database: pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'OFFSET'. (102) (SQLExecDirectW)") I only added one more condition before adding the OFFSET keyword.
1 parent d7239a9 commit f59b59b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mssql/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
364364
# Django 2.x. See https://github.com/microsoft/mssql-django/issues/12
365365
# Add OFFSET for all Django versions.
366366
# https://github.com/microsoft/mssql-django/issues/109
367-
if not (do_offset or do_limit):
367+
if not (do_offset or do_limit) and supports_offset_clause:
368368
result.append("OFFSET 0 ROWS")
369369

370370
# SQL Server requires the backend-specific emulation (2008 or earlier)

0 commit comments

Comments
 (0)