Skip to content

fix: rescale decimal results in floor and ceil to scale 0#20793

Open
skushagra wants to merge 1 commit intoapache:mainfrom
skushagra:fix/decimal-floor-ceil-scale
Open

fix: rescale decimal results in floor and ceil to scale 0#20793
skushagra wants to merge 1 commit intoapache:mainfrom
skushagra:fix/decimal-floor-ceil-scale

Conversation

@skushagra
Copy link
Contributor

Which issue does this PR close?

Which issue does this PR fix?

Fixes FLOOR('-999.9'::DECIMAL(4,1)) producing a "Decimal overflow" error instead of returning -1000. Same issue affected CEIL for the positive boundary case.

What changes are included in this PR?

  • decimal.rs — Modified apply_decimal_op to:
    • Set output type to Decimal(p, 0).
    • Rescale the result to scale 0.
    • Validate the rescaled value against Decimal(p, 0)
  • floor.rs — Updated return_type to return Decimal(p, 0) for all decimal inputs
  • ceil.rs — Same return_type change as floor

Are these changes tested?

Yes

Are there any user-facing changes?

Yes. This changes the behaviour of the floor and ceil functions

@github-actions github-actions bot added the functions Changes to functions implementation label Mar 8, 2026
@skushagra
Copy link
Contributor Author

It seems some tests require the scale to be preserved. Ill look into this and update.

@skushagra
Copy link
Contributor Author

@MichaelScofield can I get some help here. I can update the testcases to accept the new behaviour, but is this new design really required?

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

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLOOR decimal returns unexpected error

2 participants