Created
March 30, 2017 13:30
-
-
Save Xowap/3f53808d0cba8883cdb8288366e3273f to your computer and use it in GitHub Desktop.
Romanize numbers inside a string (turn "4" to "IV", and so on)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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