Skip to content

json: fix AsText() quoting of non-finite float values#170833

Draft
michae2 wants to merge 1 commit into
cockroachdb:masterfrom
michae2:fix-jsonb-nan-extraction
Draft

json: fix AsText() quoting of non-finite float values#170833
michae2 wants to merge 1 commit into
cockroachdb:masterfrom
michae2:fix-jsonb-nan-extraction

Conversation

@michae2
Copy link
Copy Markdown
Collaborator

@michae2 michae2 commented May 22, 2026

jsonNumber.AsText() was delegating to jsonNumber.String(), which goes through Format() and wraps non-finite values (NaN, +Inf, -Inf) in quotes for valid JSON serialization. This caused the ->> operator to return "NaN" instead of NaN, making (jsonb ->> key)::float fail with "could not parse" errors—a problem hit by the sql activity update job.

Fix by calling apd.Decimal.String() directly in AsText(), bypassing the JSON quoting. This matches jsonString.AsText() which also strips JSON encoding.

Fixes: #170623
Release note (bug fix): Fixed a bug where extracting non-finite float values (NaN, Infinity, -Infinity) from JSONB using the ->> operator returned quoted strings (e.g. "NaN"), causing ::float casts to fail.

jsonNumber.AsText() was delegating to jsonNumber.String(), which goes
through Format() and wraps non-finite values (NaN, +Inf, -Inf) in
quotes for valid JSON serialization. This caused the ->> operator to
return "NaN" instead of NaN, making (jsonb ->> key)::float fail with
"could not parse" errors—a problem hit by the sql activity update job.

Fix by calling apd.Decimal.String() directly in AsText(), bypassing the
JSON quoting. This matches jsonString.AsText() which also strips JSON
encoding.

Fixes: cockroachdb#170623
Release note (bug fix): Fixed a bug where extracting non-finite float
values (NaN, Infinity, -Infinity) from JSONB using the ->> operator
returned quoted strings (e.g. "NaN"), causing ::float casts to fail.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 22, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

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.

sql: TestSqlActivityUpdateTopLimitJob failed

2 participants