Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 1ddd783

Browse files
committed
fix mssql limit_select
1 parent 8cfcb9b commit 1ddd783

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

data_diff/databases/mssql.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,21 @@ def is_distinct_from(self, a: str, b: str) -> str:
113113
def limit_select(
114114
self,
115115
select_query: str,
116-
offset: Optional[int] = None,
117-
limit: Optional[int] = None,
118-
has_order_by: Optional[bool] = None,
116+
offset: int | None = None,
117+
limit: int | None = None,
118+
has_order_by: bool | None = None,
119119
) -> str:
120120
if offset:
121121
raise NotImplementedError("No support for OFFSET in query")
122-
123122
result = ""
124123
if not has_order_by:
125124
result += "ORDER BY 1"
126125

127126
result += f" OFFSET 0 ROWS FETCH NEXT {limit} ROWS ONLY"
128-
return f"SELECT * FROM ({select_query}) AS LIMITED_SELECT {result}"
127+
128+
# mssql requires that subquery columns are all aliased, so
129+
# don't wrap in an outer select
130+
return f"{select_query} {result}"
129131

130132
def constant_values(self, rows) -> str:
131133
values = ", ".join("(%s)" % ", ".join(self._constant_value(v) for v in row) for row in rows)

0 commit comments

Comments
 (0)