Re: [PATCH] Add roman support for to_number function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hunaid Sohail <hunaidpgml(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Maciek Sakrejda <m(dot)sakrejda(at)gmail(dot)com>, Tomas Vondra <tomas(at)vondra(dot)me>
Subject: Re: [PATCH] Add roman support for to_number function
Date: 2025-01-21 15:48:56
Message-ID: 3346875.1737474536@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hunaid Sohail <hunaidpgml(at)gmail(dot)com> writes:
> The leading spaces are consumed in the RN (from the main loop
> in Num_processor), and this behavior seems consistent with how
> simple numbers are handled. The Roman numeral parsing
> appears to start from where "RN" is in the format after
> leading spaces are consumed.

Yes, a space in the format string should consume a character
from the input (whether it's a space or not).

regression=# select to_number('x123', '999');
to_number
-----------
12
(1 row)

regression=# select to_number('x123', ' 999');
to_number
-----------
123
(1 row)

I used to think that a space in the format would consume any number of
spaces from the input, but that doesn't seem to be true --- I think
I was misled by that perhaps-bug in NUM_numpart_from_char. For
example:

regression=# select to_number(' 123', ' 999');
to_number
-----------
12
(1 row)

One of the three input spaces is eaten by the format space, and
one is taken as the sign, and then the 9's match ' 12'. (I don't
think we should be expecting a sign in RN though.) However,
as we add more input spaces:

regression=# select to_number(' 123', ' 999');
to_number
-----------
12
(1 row)

regression=# select to_number(' 123', ' 999');
to_number
-----------
1
(1 row)

This is bizarrely inconsistent, and I think what's causing it
is the extra space-consumption in NUM_numpart_from_char.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-01-21 15:52:51 Re: Pre-allocating WAL files
Previous Message Ivan Kush 2025-01-21 15:46:41 Re: pg_stat_statements: improve loading and saving routines for the dump file