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 1xMgsh-000000029Tv-3E4t for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:32 +0000 Received: from localhost ([127.0.0.1]:51180 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMgsf-00000008qJl-1x2o for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:33818) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMJhG-00000002yMw-3TSs for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:33:10 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMJhC-00000001Xm9-0ntR for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:33:10 +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=Qhr6d58F5g5whzudZxxDDVdq1Os4gW35kM7TctuARY0=; b=Qm5d/O1Eg7s74UAjjq8+jtHjZQ yR2Sdhz32zc36B+1rkaL1WQrBNBj54q4BAjimxxPgr+hy7Rlx8THSyLuvwL6fL+bna0ldN8G4oGQZ 5Xe0cBsM/ioCcsoZlyFWNBAi2g2em+IE56HKy12Aw03hkOtPr44/PhoURGtNfDnrbY8wic4C278OH JKTP7/Lc9YXU0wO3NWnVHAjhbWfTxF+7wImXM+IO/rqk8zuTTLduvn6kBEcmE5IlYqU2Q1klv1PQm Y+Qd9hRYOLWyX4LhKgFY64Miv/frErMyWOB01KkPEKmivP45NvpAhW2zZqmh/jVY95uYHWO3kJrwd RQ3v1R2w==; 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 1xMJhB-00000004HZi-0CC8 for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:33:05 +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 1xMJh8-00000005bli-3REg for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:33:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19810: to_char(): float V-format overflow yields 'Infinity' or NaN; format after decimal point dropped 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: Thu, 29 Oct 2026 06:32:46 +0000 Message-ID: <19810-e14756b84da7afc8@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: 19810 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux x86_64 Description: =20 Two independent issues in to_char() formatting. Issue 1: float4/float8 V (decimal shift) format has no overflow check. The V template multiplies the value by 10^n, where n is the number of digits after V. For the float types the scale factor is computed as a double; when 10^n itself overflows, the multiplication silently produces Infinity or NaN, and to_char() returns that as literal text. - A perfectly representable result is destroyed: to_char(1e-300::float8, 'FM9V' || repeat('9', 309)) -> "Infinity" The true result is 1e-300 * 10^309 =3D 1e9; the same format with numeric returns 1000000000. - Zero becomes NaN: to_char(0::float8, 'FM9V' || repeat('9', 309)) -> "NaN" (0 * inf) float4 already does this at n =3D 39. - Ordinary overflow returns literal text instead of "#" or an error: to_char(1e308::float8, 'FM9V9999999') -> "Infinity" while the equivalent SQL arithmetic 1e308::float8 * 1e7 raises ERROR: value out of range: overflow and the sibling int8 path raises "bigint out of range". One fewer 9, to_char(1e308::float8, 'FM9V999999'), returns "#######" - the documented overflow marker - so two adjacent format widths disagree on how overflow is represented. - An already-infinite input is also inconsistent within the same function: to_char('Infinity'::float8, 'FM9999') -> "####" to_char('Infinity'::float8, 'FM9999999999') -> "Infinity" The sibling branches are guarded (int4/int8 raise errors, numeric is exact); only the float4/float8 paths lack the check. Issue 2: template patterns after the decimal point are silently dropped, losing the sign. SG and PL are documented template patterns and work before or after the digit positions. Placed after the decimal point they are silently dropped - together with any literal text that follows - and the sign is lost: to_char('-100'::numeric, 'FM999') -> '-100' (default minus, correct) to_char('-100'::numeric, 'FM999.SG') -> '100' (sign lost) to_char('-100'::numeric, 'FM999.SG "items"') -> '100' (sign and literal text lost) to_char('123.4'::numeric, 'FM999.PL') -> '123' ('+' and even the fraction dropped) to_char('-100'::numeric, '999.SG') -> '100' Controls - the same patterns work correctly in adjacent positions: to_char('-100'::numeric, 'FMSG999') -> '-100' to_char('123.4'::numeric, 'FM999PL') -> '123.4+' to_char('-100'::numeric, 'FM999MI') -> '100-' A negative number formatted with a format string that contains a sign pattern (SG) must not render as an unsigned positive number.