Skip to content

bug: MSSQL dialect rewrites STDEV (sample) to STDEVP (population) when round-tripping SQL through Backend.sql() #12057

Description

@JonaGeishauser

What happened?

ibis.backends.sql.dialects.MSSQL maps the bare Stddev node to STDEVP (population):
sge.Stddev: rename_func("stdevp")
so raw T-SQL passed to Backend.sql() on the MSSQL backend is executed with different statistical semantics than submitted. This is a same-dialect round-trip (T-SQL in, T-SQL out, same backend) — not cross-dialect transpilation ambiguity.

What version of ibis are you using?

12.0.0 (sqlglot 30.4.2)

What backend(s) are you using, if any?

MSSQL (same mapping pattern present in the MySQL and Oracle dialects)

Relevant log output

import sqlglot
from ibis.backends.sql.dialects import MSSQL
print(sqlglot.transpile("SELECT STDEV([x]) AS [s] FROM [t]", read=MSSQL, write=MSSQL)[0])
# SELECT STDEVP([x]) AS [s] FROM [t]

print(sqlglot.transpile("SELECT STDEV([x]) AS [s] FROM [t]", read="tsql", write="tsql")[0])

# SELECT STDEV([x]) AS [s] FROM [t]   <- vanilla sqlglot is correct

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior inside of ibis

    Type

    No type

    Projects

    Status
    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions