Skip to content

Instantly share code, notes, and snippets.

@Xowap
Created March 30, 2017 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xowap/3f53808d0cba8883cdb8288366e3273f to your computer and use it in GitHub Desktop.
Save Xowap/3f53808d0cba8883cdb8288366e3273f to your computer and use it in GitHub Desktop.
Romanize numbers inside a string (turn "4" to "IV", and so on)
create or replace
function romanize_numbers(s text)
returns text
as $$
select
string_agg(
m [1] ||
case when char_length(m [2]) between 1 and 3
then trim(to_char(m [2] :: int, 'RN'))
else m [2]
end,
''
)
from
regexp_matches(s, '([^0-9]*)([0-9]*)', 'g') m;
$$
language sql
immutable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment