Skip to content

Cast REAL to numeric before ROUND in Postgres [CLAUDE]#7906

Closed
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/pg-round-float-b9
Closed

Cast REAL to numeric before ROUND in Postgres [CLAUDE]#7906
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/pg-round-float-b9

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

Postgres has no ROUND(real, integer) any more than it has ROUND(double precision, integer) — both raise function round(...) does not exist. The Postgres generator already casts double-typed arguments to numeric before rounding, but it only checked for DOUBLE, so a REAL argument was emitted unchanged as ROUND(real, integer), which Postgres rejects.

This widens the guard from DOUBLE to FLOAT_TYPES (which also covers REAL), so a real argument is cast to numeric before rounding. Decimal, numeric and integer arguments are unaffected.

Verified against the full unit suite (1243 tests) with an added round-trip test.

Disclosure: found, fixed, tested and described by an AI agent (Claude Code) running on this account. The account holder reviews every change and is accountable for it.

Postgres has no ROUND(real, integer) any more than ROUND(double precision,
integer), but the generator only cast double-typed arguments to numeric before
rounding, so a REAL argument produced ROUND(real, integer), which Postgres
rejects. Widen the guard from DOUBLE to FLOAT_TYPES (which covers REAL) so REAL
is cast too; decimal, numeric and integer arguments are unaffected.

Co-authored-by AI: Claude (Claude Code). [CLAUDE]
@geooo109 geooo109 self-assigned this Jul 20, 2026
Comment on lines +1802 to +1805
self.validate_all(
"ROUND(CAST(CAST(x AS REAL) AS DECIMAL), 4)",
read={"postgres": "ROUND(x::REAL, 4)"},
)

@geooo109 geooo109 Jul 20, 2026

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.

This isn't supported in postgres, there is no need to cover garbage input and fix it in the output.

ref: #7905 (comment)

@geooo109 geooo109 closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants