Modernize to_char's Roman-numeral code, fixing overflow problems.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 26 Sep 2024 15:02:31 +0000 (11:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 26 Sep 2024 15:02:31 +0000 (11:02 -0400)
commit147bbc90f75794e5522dcbadaf2bbe1af3ce574a
treee84f92a11a5b766109dc51fe062d56e87cf41030
parente3a92ab0708aa8ac0c8466312cef316ea6d03c63
Modernize to_char's Roman-numeral code, fixing overflow problems.

int_to_roman() only accepts plain "int" input, which is fine since
we're going to produce '###############' for any value above 3999
anyway.  However, the numeric and int8 variants of to_char() would
throw an error if the given input exceeded the integer range, while
the float-input variants invoked undefined-per-C-standard behavior.
Fix things so that you uniformly get '###############' for out of
range input.

Also add test cases covering this code, plus the equally-untested
EEEE, V, and PL format codes.

Discussion: https://postgr.es/m/2956175.1725831136@sss.pgh.pa.us
doc/src/sgml/func.sgml
src/backend/utils/adt/formatting.c
src/test/regress/expected/int8.out
src/test/regress/expected/numeric.out
src/test/regress/sql/int8.sql
src/test/regress/sql/numeric.sql