Skip to content

Add STDDEV as case-insensitive alias of stddevPop - #105120

Merged
alexey-milovidov merged 3 commits into
masterfrom
alias-stddev
May 18, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
alias-stddev

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 16, 2026 •

Copy link
Copy Markdown
Member

PostgreSQL/SQL-standard STDDEV is the standard short form for the sample standard deviation (denominator n - 1). PostgreSQL, Oracle, BigQuery, Snowflake, and DuckDB all alias it to STDDEV_SAMP. This PR adds STDDEV as a case-insensitive alias of stddevSamp so that PostgreSQL-dialect queries (e.g., the SQLStorm corpus) do not need rewriting and do not silently change results.

ClickHouse already exposes STDDEV_POP, STDDEV_SAMP, and STD (the MySQL-style population alias), so this is purely additive.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added STDDEV as a case-insensitive alias of stddevSamp for PostgreSQL/SQL-standard compatibility.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.786

PostgreSQL/SQL-standard `STDDEV` is the standard short form for the
population standard deviation. ClickHouse already exposes the related
synonyms `STDDEV_POP`, `STDDEV_SAMP`, `STD`; add `STDDEV` to spare
PostgreSQL-dialect workloads a rewrite when querying ClickHouse.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [032191b]

Summary: ✅


AI Review

Summary

The PR adds STDDEV as a case-insensitive alias to stddevSamp and adds a focused stateless test proving STDDEV/stddev/Stddev resolve to sample standard deviation semantics. The previously reported compatibility issue (mapping to stddevPop) is addressed in current head, and no remaining correctness, safety, or compatibility issues were found in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 16, 2026
alexey-milovidov added a commit that referenced this pull request May 16, 2026
Recent compatibility PRs added case-insensitive aliases and parser sugar
that make several of the SQLStorm rewrites unnecessary:

  - `STDDEV`            -> `stddevPop`            (#105120)
  - `array_to_string`   -> `arrayStringConcat`    (#105121)
  - `REGEXP_SUBSTR`     -> `regexpExtract`        (#105122)
  - `CARDINALITY`       -> `length`               (#105123)
  - `unnest()` function -> `arrayJoin()`          (#105124)
  - `STRING_AGG`        -> `groupConcat`          (#105125)
  - `date_part(unit,e)` -> `EXTRACT(unit FROM e)` (#105127)
  - `expr OP ANY/ALL(array_literal)`              (#105129)

`ARRAY_AGG`, `TRANSLATE`, and `EXTRACT(EPOCH|DOW|... FROM ...)` were
already supported by ClickHouse before these PRs.

Removed the corresponding rewrite calls and helper functions
(`rewrite_string_agg`, `rewrite_array_agg`, `rewrite_date_part`,
`rewrite_stddev`, `rewrite_extract_epoch`, the EXTRACT(DOW) inline
rewrite, `rewrite_any_comparison`, and the trailing
`unnest(...) -> arrayJoin(...)` substitution). Also dropped the
unreferenced no-op helpers (`rewrite_extract_unit`, `rewrite_fetch_offset`,
`rewrite_interval`, `rewrite_cast_timestamp`, `rewrite_current_timestamp`,
`rewrite_bool_literals`, `rewrite_ilike`, `rewrite_no_supertype`).

The PostgreSQL `LATERAL` / `CROSS JOIN UNNEST(...)` table-source forms,
`arrayJoin(...)` in JOIN position, PG-specific casts, `AT TIME ZONE`,
`STRING_AGGDistinct` (a mangled-name artifact), and the still-unsupported
function rewrites (`string_to_array`, `regexp_split_to_array`, `RANDOM`,
`TO_TIMESTAMP`, `ARRAY_LENGTH`, `SPLIT_PART`, `age`) are still rewritten.

Net change: -329 lines from rewrite_queries.py and -75 lines from the
tests (the `TestRewriteAnyComparison` class is removed since the rewrite
it covered no longer exists).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
PostgreSQL, Oracle, BigQuery, Snowflake, and DuckDB all treat `STDDEV` as
the sample standard deviation (`STDDEV_SAMP`, denominator `n - 1`), not
the population one. Mapping it to `stddevPop` would silently change
results for PostgreSQL-dialect queries (e.g., the SQLStorm corpus) that
this alias was added to support.

Re-point `STDDEV` to `stddevSamp` and update the test accordingly. `STD`
stays mapped to `stddevPop` because that matches MySQL semantics.

Addresses #105120 (comment)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.20% 84.20% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 100.00% (5/5) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 18, 2026
Merged via the queue into master with commit 04dbbf8 May 18, 2026
166 checks passed
@alexey-milovidov
alexey-milovidov deleted the alias-stddev branch May 18, 2026 23:58
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants