Skip to content

fix(mssql,oracle): render bare Stddev as sample standard deviation - #12161

Merged
deepyaman merged 8 commits into
ibis-project:mainfrom
bhargaviHQ:fix/mssql-oracle-stddev-sample
Oct 18, 2026
Merged

deepyaman merged 8 commits into
ibis-project:mainfrom
bhargaviHQ:fix/mssql-oracle-stddev-sample

Conversation

@bhargaviHQ

@bhargaviHQ bhargaviHQ commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description of changes

The MSSQL dialect mapped a bare sge.Stddev to STDEVP, but T-SQL's STDEV is the sample standard deviation, so STDEV in user SQL was silently turned into a population one. Oracle had the same problem: STDDEV became STDDEV_POP, even though Oracle's STDDEV is sample. This shows up through Table.sql() and con.sql(..., dialect=...), not Backend.sql() without a dialect. It also affected cross-dialect queries, e.g. a DuckDB or Postgres STDDEV sent to MSSQL or Oracle came back as the population value.

This removes the sge.Stddev overrides for MSSQL and Oracle, so sqlglot's defaults are used, which already render STDEV and STDDEV. Since the Oracle override was applied to sqlglot's global Oracle dialect, removing it also fixes plain sqlglot.transpile(..., write="oracle") for anyone who imported ibis. SQL generated from ibis expressions like t.x.std() doesn't change, since that always goes through stddev_samp/stddev_pop.

Tests: test_dot_sql_transpile_stddev in test_dot_sql.py runs DuckDB SQL over a few rows on every backend and compares against the sample standard deviation (with markers for SQLite, Druid, RisingWave and BigQuery, where the query can't run as written).

MySQL isn't changed here. sqlglot parses MySQL's STDDEV/VARIANCE (population) into the same nodes as DuckDB's sample versions, so fixing that needs a change in sqlglot (tobymao/sqlglot#8626). MySQL and SingleStoreDB are marked notyet in the new test for now.

Issues closed

@github-actions github-actions Bot added tests Issues or PRs related to tests sql Backends that generate SQL mssql The Microsoft SQL Server backend oracle The Oracle backend labels Oct 12, 2026
Comment thread ibis/backends/sql/dialects.py Outdated
Comment thread ibis/backends/sql/dialects.py Outdated
Comment thread ibis/backends/tests/sql/test_sql.py Outdated
Comment thread ibis/backends/mssql/tests/test_client.py Outdated
Comment thread ibis/backends/oracle/tests/test_client.py Outdated
@deepyaman deepyaman changed the title fix(mssql/oracle): render bare Stddev as sample standard deviation fix(mssql,oracle): render bare Stddev as sample standard deviation Oct 13, 2026
…ddev-sample

# Conflicts:
#	ibis/backends/sql/tests/test_compiler.py
…ddev-sample

# Conflicts:
#	ibis/backends/tests/test_dot_sql.py

@deepyaman deepyaman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor comments, and then it looks good

Comment thread ibis/backends/sql/tests/test_compiler.py Outdated
Comment thread ibis/backends/tests/test_dot_sql.py Outdated
Co-authored-by: Deepyaman Datta <deepyaman.datta@utexas.edu>
@deepyaman
deepyaman self-requested a review October 16, 2026 20:55
@deepyaman
deepyaman enabled auto-merge (squash) October 16, 2026 20:56
Comment thread ibis/backends/sql/tests/test_compiler.py Outdated
Comment thread ibis/backends/sql/tests/test_compiler.py Outdated
@deepyaman
deepyaman merged commit d6e6811 into ibis-project:main Oct 18, 2026
82 of 83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mssql The Microsoft SQL Server backend oracle The Oracle backend sql Backends that generate SQL tests Issues or PRs related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants