added logic for modulo function for pyodbc driver (#8853)

This commit is contained in:
Teddy 2022-11-18 09:41:36 +01:00 committed by GitHub
parent be59a78a49
commit d680d5d2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -58,7 +58,7 @@ def _(elements, compiler, **kwargs):
@compiles(MedianFn, Dialects.MSSQL)
def _(elements, compiler, **kwargs):
"""Median computation for MSSQL"""
col, _ = [compiler.process(element, **kwargs) for element in elements.clauses]
col = elements.clauses.clauses[0].name
return "percentile_cont(0.5) WITHIN GROUP (ORDER BY %s ASC) OVER()" % col

View File

@ -74,3 +74,13 @@ def _(element, compiler, **kw):
"""SQLite modulo function"""
value, base = validate_and_compile(element, compiler, **kw)
return f"{value} % {base}"
@compiles(ModuloFn, Dialects.MSSQL)
def _(element, compiler, **kw):
"""Azure SQL modulo function"""
value, base = validate_and_compile(element, compiler, **kw)
if compiler.dialect.driver == "pyodbc":
# pyodbc compiles to c++ code.
return f"{value} % {base}"
return f"{value} %% {base}"