从PostgreSQL中的数字获取月份名称 [英] Get month name from number in PostgreSQL
本文介绍了从PostgreSQL中的数字获取月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,列有 month
( integer
)。在这一列中,我存储值如 1,2,... 12
。
但是我必须显示月份名称
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.
例如:
如果值为 1
我需要显示 jan
。
推荐答案
基本上,@small_duck已经发布,但有一些改进:
Basically what @small_duck already posted, but a couple of improvements:
SELECT to_char(to_timestamp (4::text, 'MM'), 'TMmon')
-
简单的转换为文本
4 :: text
是足够的,不需要to_char(..)
。问题要求小写 jan,则有一个模板模式 :
mon
。Question asks for lower case "jan", there is a template pattern for that:
mon
.如果要本地化输出,请使用修饰符
TM
。If you want to localize the output, prefix the template with the modifier
TM
.这篇关于从PostgreSQL中的数字获取月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文