BUG #19652: to_number() silently truncates over-length integers - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19652: to_number() silently truncates over-length integers
Date
Msg-id 19652-53cdb1205ea93a19@postgresql.org
Whole thread
Responses Re: BUG #19626: Segmentation fault planning self-join IN subquery with LATERAL UNION ALL
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19652
Logged by:          chunling qin
Email address:      303677365@qq.com
PostgreSQL version: 18.6
Operating system:   x86_64
Description:

When the number of integer digits exceeds what the format template provides,
the excess digits are silently dropped. The very same input with a decimal
point added raises an overflow error — one "value exceeds the format"
scenario, two opposite behaviors:

SELECT to_number('1234567', '999');
-- 123               (digits beyond the 3-digit format silently discarded)

SELECT to_number('1234567.89', '999.99');
-- ERROR:  numeric field overflow
-- DETAIL:  A field with precision 3, scale 0 must round to an absolute
value
-- less than 10^3.

Both inputs should raise an error ("value too long" / overflow), since the
integral part exceeds the format in both cases; silently returning 123 for
'1234567' loses the high-order digits without any diagnostic.





pgsql-bugs by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: REPACK (CONCURRENTLY) doesn't handle invalid indexes
Next
From: Edwin Polkerman
Date:
Subject: Re: BUG #19647: Difference in pg_basebackup behaviour between PostgreSQL <= 16 and >= 17 with pgactive extension