sql - PostgreSQL: How to return roman date with single space delimitation elegantly? -
if use standard way receive date roman-numeric months ...
select to_char(date '2000 12 05', 'dd rm yyyy')
postgresql returns multi-spaced (1 4) delimited dates:
"05 xii 2000" "02 viii 1976" "02 v 1976"
i notice rm
returns 5 characters possibilities of month (from small: i
big: viii
)
this not expected. want single-spaced delimited dates returned. came solution using regex_replace might overkill (?)
select regexp_replace(to_char(date '2000 12 05', 'dd rm yyyy'), '(\d+)\s+([ivx]+)\s+(\d+)',e'\\1 \\2 \\3','g');
which returns single-spaced date results:
"05 xii 2000" "02 viii 1976" "02 v 1976"
is there more elegant way this? (...or post bug in postgresql?)
simply add fm
:
fm suppresses leading zeroes , trailing blanks otherwise added make output of pattern fixed-width.
select to_char(date '2000 01 05', 'dd fmrm yyyy'); -- 05 2000
Comments
Post a Comment