Re: [PATCH] Add roman support for to_number function

Aleksander Alekseev <aleksander@timescale.com>

From: Aleksander Alekseev <aleksander@timescale.com>
To: pgsql-hackers@postgresql.org
Cc: Hunaid Sohail <hunaidpgml@gmail.com>, Maciek Sakrejda <maciek@pganalyze.com>, maciek@sakrejda.org
Date: 2024-09-05T09:41:42Z
Lists: pgsql-hackers
Hi,

> I have attached a new patch v2 with following changes:
>
> - Handled invalid cases like 'viv', 'lxl', and 'dcd'.
> - Changed errcode to 22P07 because 22P06 was already taken.
> - Removed TODO.
> - Added a few positive & negative tests.
> - Updated documentation.
>
> Looking forward to your feedback.

While playing with the patch I noticed that to_char(..., 'RN') doesn't
seem to be test-covered. I suggest adding the following test:

```
WITH rows AS (
    SELECT i, to_char(i, 'FMRN') AS roman
    FROM generate_series(1, 3999) AS i
) SELECT bool_and(to_number(roman, 'RN') = i) FROM rows;

 bool_and
----------
 t
```

... in order to fix this while on it. The query takes ~12 ms on my laptop.

-- 
Best regards,
Aleksander Alekseev



Commits

  1. Support RN (roman-numeral format) in to_number().