Skip to content

Preserve precision for numeric power functions - #339

Open
fallintoplace wants to merge 1 commit into
ClickHouse:mainfrom
fallintoplace:fix/numeric-power-precision
Open

Preserve precision for numeric power functions#339
fallintoplace wants to merge 1 commit into
ClickHouse:mainfrom
fallintoplace:fix/numeric-power-precision

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

ClickHouse evaluates pow() as Float64, so pushing down PostgreSQL numeric overloads can round values before an exact comparison. Keep float8 pushdown, but evaluate numeric pow() and power() locally in PostgreSQL.

The regression uses a Decimal128 source value to cover both function names: the exact PostgreSQL result matches, while the rounded Float64 result does not.

Testing

  • Extension builds and installs with -Werror
  • Numeric power regression verified with PostgreSQL 19 and ClickHouse 26.7

@fallintoplace
fallintoplace marked this pull request as draft August 3, 2026 23:56
@fallintoplace
fallintoplace marked this pull request as ready for review August 3, 2026 23:58

@theory theory 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.

ClickHouse pow() takes a Decimal value, so we should be able to evaluate numerics without loss of precision.

@theory theory added the functions Improve function pushdown label Aug 6, 2026
@theory

theory commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Oh I see, it returns Float64. I don't know whether this loss of precision matters, though.

@fallintoplace

Copy link
Copy Markdown
Contributor Author

Yes, it matters for exact comparisons. In ClickHouse 26.7, pow(Decimal128(...), 2) accepts Decimal input but returns Float64, producing 1.5241578753238834 instead of PostgreSQL’s exact numeric result 1.524157875323883675. The regression demonstrates that pushing it down changes the result, so numeric pow()/power() should remain local while float8 remains pushed down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Improve function pushdown

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants