to_char() on integer with V format silently wraps on overflow
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
This thread has been committed, so CI has stopped here. Anything below is the last result it produced.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253399psql -h localhost -U postgresBuilt from patchset v1 (message #1), August 31, 2026 at 01:18 PM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t253399_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t253399_1 && git checkout t253399_1Patchset v1 (message #1) is on t253399_1
Hi, All!
to_char() with a V format multiplies the value by 10^n. For integer
input that multiply is a bare int32 expression. On overflow the
product wraps and to_char() prints the wrapped digits. There is no
error. The same call on bigint is correct. Plain integer multiply
already raises "integer out of range".
SELECT to_char(3, '9V999999999');
-- actual: -1294967296
-- expected: ERROR: integer out of range
SELECT to_char(2147483647, '9V9');
-- actual: -10
-- expected: ERROR: integer out of range
SELECT to_char(3::bigint, '9V999999999');
-- 3000000000
SELECT 3 * 1000000000;
-- ERROR: integer out of range
Cause: int4_to_char() does value * (int32) pow(10, multi) with no
overflow check. int8_to_char() already uses int8mul and dtoi8.
The attached patch uses int4mul and dtoi4 for the same step with regress
tests.
Thoughts?
--
Regards,
Rachitskiy Andrey
Hi Andrey
Nice catch! I successfully ran all the tests locally.
LGTM!
Kind regards,
Miłosz Bieniek
On Thu, Aug 27, 2026 at 5:57 PM Miłosz Bieniek <bieniek.milosz@proton.me> wrote:
Hi Andrey
Nice catch! I successfully ran all the tests locally.
LGTM!
The patch looks good to me, too.
Barring any objections, I'll commit it.
Regards,
--
Fujii Masao
чт, 27 авг. 2026 г. в 15:30, Fujii Masao <masao.fujii@gmail.com>:
On Thu, Aug 27, 2026 at 5:57 PM Miłosz Bieniek
Nice catch! I successfully ran all the tests locally.
LGTM!The patch looks good to me, too.
Barring any objections, I'll commit it.Dear Miłosz and Fujii-san,
Thanks for the review.
--
Regards,
Rachitskiy Andrey