query_int wrongly parses zero-padded input

From: Marko Grujic <marko(dot)grujic(at)enterprisedb(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: query_int wrongly parses zero-padded input
Date: 2026-10-17 20:17:54
Message-ID: CAOvwyF3=brZoxwcwHRQqvLjuqSqxiTN7RXpKMNHXJ1WAS5GQ2Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I'm reporting a minor, long-standing, edge case in intarray here.

Namely, when parsing a query_int, the strtol base is set to 0, which forces
the base auto-detection mode.

Consequently, when a zero-padded integer input is provided, the number is
interpreted as an octal value, which in turn leads to wrong int-query results

postgres=# select '010'::query_int;
query_int
-----------
8
(1 row)

postgres=# select '{10}'::int[] @@ '010'::query_int;
?column?
----------
f
(1 row)

I believe this is not the intended behavior; attached is a small patch that
sets the base to decimal instead (and adds the above as a regression test).

Thanks,
Marko

Attachment Content-Type Size
0001-intarray-Parse-query_int-integers-as-decimals.patch application/octet-stream 2.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Raja Sai pranav 2026-10-17 20:31:11 Re: Possible race condition in pg_basebackup
Previous Message Manu 2026-10-17 19:48:53 Re: ZSTD TOAST compression, and an extensible compression method encoding