Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xNpqC-00000002ltS-37KN for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Nov 2026 11:04:41 +0000 Received: from localhost ([127.0.0.1]:42002 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xNpqB-00000003B7K-3EM7 for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Nov 2026 11:04:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:58802) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xNQao-0000000GbJi-2pV9 for pgsql-bugs@lists.postgresql.org; Sun, 01 Nov 2026 08:07:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xNQam-00000001yY4-3Pwz for pgsql-bugs@lists.postgresql.org; Sun, 01 Nov 2026 08:07:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=YwPpwxT6OTqA7zjXX7nKM4gIxZFq9Tl9HOsw6mUCFDw=; b=H2QTpIs9zZVs67iqr0ZwBTn18P x+ZbPnJbApBBW6DnjGtx86hmGe3YICyfTzy4xoBZOVZ9uRTxcHUHHrcLf3YE2cVJ3gS8eE1JwehkL uKeQY4qZc5bOJX4Fjzdlo87LsjO/vbOc1SHSX0m5Yro7Fu9UFFVpGWNj5fH3eIyRI5E+4DFBrwkbs 2D5I1ovp30sYnmC90UeNosx2neESz73hHkrzDKZjdTitHihf5k2PoN2IFq2vw/VFYTxoDhYiK2FjQ 5ajtwfdGIrAil5YbWYSUXHO07gjhUVbeITD7uP6ztx1iYuaNzCdFJPXk3JwuJopnZZTFiGXxw2MV6 z90KWyYQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xNQam-00000005k0F-2IEV for pgsql-bugs@lists.postgresql.org; Sun, 01 Nov 2026 08:07:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xNQak-00000009tK8-1n6X for pgsql-bugs@lists.postgresql.org; Sun, 01 Nov 2026 08:07:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19823: JSON_VALUE(... RETURNING jsonb) silently returns NULL for PASSING values of NaN / Infinity; the expo To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Sun, 01 Nov 2026 08:06:12 +0000 Message-ID: <19823-17cb42c43b9ee661@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19823 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux (TencentOS 4.4, x86_64) Description: =20 Hello, When a PASSING variable holds a numeric NaN or Infinity, JSON_VALUE with RETURNING jsonb silently returns NULL. With ERROR ON ERROR the swallowed error surfaces, and it points at JSON parsing rather than at the numeric encoding that actually failed: SELECT JSON_VALUE(jsonb '{}', '$x' PASSING 'NaN'::numeric AS x RETURNING jsonb) AS nan_default; -- actual: (NULL) expected: "NaN", like every other path below SELECT JSON_VALUE(jsonb '{}', '$x' PASSING 'Infinity'::float8 AS x RETURNING jsonb) AS inf_default; -- actual: (NULL) -- adding ERROR ON ERROR exposes what was swallowed: SELECT JSON_VALUE(jsonb '{}', '$x' PASSING 'NaN'::numeric AS x RETURNING jsonb ERROR ON ERROR); -- ERROR: 22P02: invalid input syntax for type json -- DETAIL: Token "NaN" is invalid. -- CONTEXT: JSON data, line 1: NaN The same value survives on every other path, so only the jsonb-encoding route of JSON_VALUE drops it: RETURNING numeric / text / float8 -> NaN / Infinity (kept) JSON_QUERY(..., RETURNING jsonb) same args -> NaN (kept) JSON_TABLE(... COLUMNS (j jsonb ...)) -> NaN, jsonb_typeof =3D number to_jsonb('NaN'::numeric) -> "NaN" (kept) Expected: the jsonb rendering of a PASSING variable should agree with to_jsonb() / JSON_QUERY() / JSON_TABLE() (which encode NaN as the string "NaN"); at minimum, if the value cannot be encoded, the error raised under ERROR ON ERROR should be attributed to the numeric encoding step, not reported as a JSON parse error. Actual: the field silently disappears from the output (NULL), and the error message, when forced out, misattributes the cause. For context, this is the same family as the timestamptz PASSING rendering difference (same jsonb-encoding route of PASSING values), but the mechanism is distinct and the impact is silent data loss: any row whose sensor/financial value is NaN or Infinity loses that field in the JSON output, with no warning, and downstream consumers cannot tell "no data" apart from "bad data". Reproduced on: - PostgreSQL 18.6 (REL_18_STABLE, self-built, snapshot 2026-10-26) - PostgreSQL 20devel (snapshot of 2026-10-29) A draft fix location would be the numeric branch of the PASSING-to-jsonb item encoding (the caller of json_errsave_error, jsonfuncs.c:662): encode non-finite numerics the way to_jsonb() does. Regards, Chunling Qin