Skip to content

Read a string literal in an aggregate call as PostgreSQL resolves it - #3030

Merged
tamnd merged 1 commit into
mainfrom
pg4-aggregate-unknowns
Oct 12, 2026
Merged

tamnd merged 1 commit into
mainfrom
pg4-aggregate-unknowns

Conversation

@tamnd

@tamnd tamnd commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Part of #2492.

PostgreSQL resolves a string literal in an aggregate call through the usual function lookup. The literal has the unknown type, and the aggregate candidates decide which type it gets. So avg('4') has two equal candidates and fails with 42725, and max('x') reads the literal as text.

The first part of this work landed in #3002 by accident, because a commit chain picked up the edit. That part resolves the unknown arguments of a plain aggregate call. This PR finishes the work:

  • A windowed aggregate call now resolves its unknown arguments too, so sum('x') over () fails with 42725 as in PostgreSQL.
  • regr_r2 kept a NaN answer as 1, because f64::min drops NaN. It now clamps only a real value above 1, so a NaN input gives NaN as in PostgreSQL.
  • A server test covers both paths and the errors.

The harness goes from 1869 to 1873 statements that are the same on rudb, with no new differences.

@tamnd tamnd added kind/bug It does the wrong thing. area/postgres-compat The PostgreSQL wire protocol, server, catalog, dialect and clients. labels Oct 12, 2026
@tamnd
tamnd merged commit 191866d into main Oct 12, 2026
1 check failed
@tamnd
tamnd deleted the pg4-aggregate-unknowns branch October 12, 2026 15:22
@tamnd tamnd mentioned this pull request Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/postgres-compat The PostgreSQL wire protocol, server, catalog, dialect and clients. kind/bug It does the wrong thing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant