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 1xDhB5-00000000efj-0Who for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 11:48:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xDhB3-00000009wVy-4AOT for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 11:48:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xDEay-0000000439n-023R for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:17:08 +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 1xDEav-00000000GR8-0uKz for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:17:07 +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=sB2DY+GUuW6twKtPIN1KmpSY8kA+9BLCE77KBmwGAB8=; b=0RDrvgpxiA0+TNproh5XtHi7XW hgGFe5w/oIN7fQSngtIihf6TSvFtiewGNX4EQuQm9H99G2ZJn0aQOAKu5w3z2goxU2jour2QoZJxC ULdWcqfO1A9mdCR8/kIGdASBZk5oQmzD7ro7Dll+b/EkeMhQJ3UZqOVDi92zVxP6yIxyAt6eQvdph 0nTEAYHCbLZq6gdRzV8CkCnlLtkoMLSpH3TEWdjx1fPhdeIcbuVO0MEUuLOrsUDpHMByjc0Iq0eQd gTFgeU0wY8GcmlZAsyNRi36iBbtGG9quUayqv3WvVRyHlpa/px9VwiRKpFj98xVAL73zXNnBrxQH4 jtJXJNHg==; 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 1xDEau-00000000ugT-2F3s for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:17: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 1xDEat-00000002RyG-1xeF for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:17:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19744: contrib/seg output truncates to 6 significant digits, breaking dump/restore To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: kehan5800@gmail.com Reply-To: kehan5800@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 04 Oct 2026 05:16:30 +0000 Message-ID: <19744-8c700582bbb1d075@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: 19744 Logged by: Ke Email address: kehan5800@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04.2 x86_64 Description: =20 The seg documentation (doc/src/sgml/seg.sgml, "Precision") says: seg values are stored internally as pairs of 32-bit floating point numbers. This means that numbers with more than 7 significant digits will be truncated. Numbers with 7 or fewer significant digits retain their original precision. That is, if your query returns 0.00, you will be sure that the trailing zeroes are not the artifacts of formatting: they reflect the precision of the original data. In practice a 7-significant-digit value is stored exactly but printed with 6 digits: CREATE EXTENSION seg; SELECT '1234567'::seg AS printed, seg_lower('1234567'::seg)::float8 AS stored, '1234567'::seg::text::seg =3D '1234567'::seg AS round_trips; printed | stored | round_trips -------------+---------+------------- 1.23457e+06 | 1234567 | f SELECT '1.234567'::seg, '0.0001234567'::seg, '1234567 .. 7654321'::seg, '1.000000'::seg; 1.23457 | 0.000123457 | 1.23457e+06 .. 7.65432e+06 | 1.00000 The last one is the "trailing zeroes" case the documentation uses as its example: seven significant digits in, six out. 1234567 is well inside float4's exact-integer range, so the storage side of the promise holds; it is the digit count that is cut. Walking the boundary: 1 to 6 significant digits print in full and round-trip; 7, 8 and 9 print as 6 and do not. Because pg_dump writes seg_out()'s text, a dump/restore changes the data: CREATE TABLE segt (s seg); INSERT INTO segt VALUES ('1234567'), ('1.234567'); $ pg_dump -t segt --data-only COPY public.segt (s) FROM stdin; 1.23457e+06 1.23457 \. and both restored values compare unequal to the originals. Cause: the per-boundary digit count (sigd) is clamped to FLT_DIG, which is 6, in two places: contrib/seg/segparse.y:177, sig_digits(): /* Clamp, to ensure value will fit in sigd fields */ return Min(n, FLT_DIG); contrib/seg/seg.c:943-946, restore() (called by seg_out()): if (n <=3D 0) n =3D FLT_DIG; else n =3D Min(n, FLT_DIG); The parse-side clamp already discards the 7th digit's worth of l_sigd/u_sigd before anything is stored, so changing restore() alone would not help. FLT_DIG is the decimal->float->decimal guarantee; the number of digits needed to reproduce a float4 from its text is FLT_DECIMAL_DIG (9). Expected: either values with up to 7 significant digits round-trip as documented, or the documentation states the actual limit (6). Actual: values with 7 significant digits are printed with 6 and do not survive their own text form or pg_dump. Possible fix: use 7 (to match the documentation) or FLT_DECIMAL_DIG (to make output exact for every stored value) in both places. Both fit the "char" sigd fields that the parse-side comment is protecting, and restore()'s 25-byte buffer still has room. The existing regression test "Digits truncated" (12.34567890123456 -> 12.3457) would change accordingly. If the 6-digit behaviour is intended, the "7 or fewer" sentence in seg.sgml should be corrected instead.