「PostgreSQL 14.4]to_char関数にRMを指定して月をローマ大文字数字で取得する方法

環境
OSバージョンの確認

# cat /etc/redhat-release
Rocky Linux release 9.0 (Blue Onyx)

PostgreSQLバージョンの確認

# psql --version
psql (PostgreSQL) 14.4

構文
to_char(date '指定日付’, 'RM’)
to_char関数にパターン「RM」を指定して、月をローマ数字で取得します。
パタンー RM
ローマ数字による月 (I-XII: I=1月) (大文字)

使用例

SELECT 
  to_char(date '2022-01-01', 'RM') AS "January",
  to_char(date '2022-02-01', 'RM') AS "February",
  to_char(date '2022-03-01', 'RM') AS "March",
  to_char(date '2022-04-01', 'RM') AS "April",
  to_char(date '2022-05-01', 'RM') AS "May",
  to_char(date '2022-06-01', 'RM') AS "June",
  to_char(date '2022-07-01', 'RM') AS "July",
  to_char(date '2022-08-01', 'RM') AS "August",
  to_char(date '2022-09-01', 'RM') AS "September",
  to_char(date '2022-10-01', 'RM') AS "October",
  to_char(date '2022-11-01', 'RM') AS "November",
  to_char(date '2022-12-01', 'RM') AS "December";

実行結果

January	February	March	April	May	June	July	August	September	October	    November	December
I   	II  	    III 	IV  	V       VI      VII 	VIII	IX  	         X   	    XI  	  XII

 

PostgreSQL

Posted by arkgame