Re: [PATCH] Add roman support for to_number function

From: Hunaid Sohail <hunaidpgml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 09:26:12
Message-ID: CAMWA6yZ+6u4Ux6DtGS+CfDYi1i3=tK5Vqyee83FvaoMr3K_HNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 21, 2025 at 1:35 PM Hunaid Sohail <hunaidpgml(at)gmail(dot)com> wrote:

> Agreed. Your changes in v7 consumes leading spaces if leading space
> is present in format (' RN'). But we need it to work on cases like:
> SELECT to_number(' XIV', 'RN');
> So, I can add this logic in my next patch.
>

So, I was playing with leading spaces in v7 and found something
interesting.

postgres=# --both input and format both 2 spaces
postgres=# SELECT to_number(' XIV', ' RN');
to_number
-----------
14
(1 row)

postgres=# --input 1 space, format 2 spaces
postgres=# --Input is read from "IV" ignoring "X"
postgres=# SELECT to_number(' XIV', ' RN');
to_number
-----------
4
(1 row)

postgres=# --should work after leading spaces are handled
postgres=# SELECT to_number(' XIV', ' RN');
ERROR: invalid Roman numeral
postgres=# select to_number('123456', ' 999999');
to_number
-----------
23456
(1 row)

postgres=# select to_number('123456', ' 999999');
to_number
-----------
3456
(1 row)

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.

Please review the first two examples of Roman numerals.
I'd appreciate your opinions on whether this behavior should be considered
valid.

Regards,
Hunaid Sohail

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2025-01-21 09:29:22 Re: [PoC] Federated Authn/z with OAUTHBEARER
Previous Message Jakub Wartak 2025-01-21 09:16:03 Re: Trim the heap free memory