sql: reject WITHIN GROUP on non-ordered-set aggregates#171369
sql: reject WITHIN GROUP on non-ordered-set aggregates#171369virajchogle wants to merge 2 commits into
Conversation
WITHIN GROUP (ORDER BY ...) was silently ignored on non-ordered-set functions. Match PostgreSQL by rejecting with SQLSTATE 42809. Fixes cockroachdb#171236 Release note (bug fix): WITHIN GROUP on a function that is not an ordered-set aggregate now returns an error matching PostgreSQL.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Hi @virajchogle, thanks for the PR! It's not showing up here, but there are some test failures. For example, here's one you can play with locally: The failure has the error You can also see this error if you start up |
|
Thanks for catching this @michae2 . Root cause is the SHOW ENUMS delegate (pkg/sql/delegate/show_enums.go:42), which uses array_agg(...) WITHIN GROUP (ORDER BY ...), the very syntax this PR rejects. Switching to array_agg(... ORDER BY ...). Tested. Pushing shortly. |
The SHOW ENUMS delegate used array_agg(...) WITHIN GROUP (ORDER BY ...), which was silently accepted before but is now rejected. Switch to array_agg(x ORDER BY y), same semantics with valid PG syntax. Release note: None
|
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
Fixes #171236
WITHIN GROUP (ORDER BY ...)is only valid on ordered-set aggregate functions (percentile_disc,percentile_cont). CockroachDB silently ignored the clause on general aggregates (sum,avg, ...) and non-aggregate scalar functions (concat_ws,abs, ...), diverging from PostgreSQL's behavior.This rejects the misuse in
scope.VisitPreagainst theisOrderedSetAggregateallowlist, usingpgcode.WrongObjectType(SQLSTATE 42809) to match PostgreSQL.Epic: none
Release note (bug fix): WITHIN GROUP on a function that is not an ordered-set aggregate now returns an error matching PostgreSQL.