fix(sql): handle ORDER BY in embedded MSSQL queries (#43127)

Co-authored-by: Bexultan Mustafin <bexultan.mustafin@ffins.kz>
Co-authored-by: Amin Ghadersohi <amin.ghadersohi@gmail.com>
This commit is contained in:
Bexultan
2026-08-14 14:07:10 -04:00
committed by GitHub
co-authored by Bexultan Mustafin Amin Ghadersohi
parent 856599027a
commit 1e65d93a83
4 changed files with 108 additions and 0 deletions
+16
View File
@@ -2824,6 +2824,22 @@ def test_as_cte_called_twice() -> None:
stmt.as_cte()
@pytest.mark.parametrize(
("sql", "removed"),
[
("SELECT value FROM source ORDER BY value", True),
("SELECT TOP 1 value FROM source ORDER BY value", False),
("SELECT value FROM source ORDER BY value OFFSET 0 ROWS", False),
("SELECT value FROM source ORDER BY value FOR JSON AUTO", False),
],
)
def test_remove_unbounded_top_level_order_by(sql: str, removed: bool) -> None:
statement = SQLStatement(sql, "mssql")
assert statement.remove_unbounded_top_level_order_by() is removed
assert ("ORDER BY" not in statement.format()) is removed
@pytest.mark.parametrize(
"sql, rules, expected",
[