Get month name from number in PostgreSQL

前端 未结 2 1339
悲&欢浪女
悲&欢浪女 2021-02-07 00:32

I have a table with a column month(integer). In this column I store values like 1, 2, .. 12.
But I have to show the month name

2条回答
  •  甜味超标
    2021-02-07 01:08

    Basically what @small_duck already posted, but a couple of improvements:

    SELECT to_char(to_timestamp (4::text, 'MM'), 'TMmon')
    
    • A plain cast to text 4::text is enough, no need for to_char(..).

    • Question asks for lower case "jan", there is a template pattern for that: mon.

    • If you want to localize the output, prefix the template with the modifier TM.

提交回复
热议问题