我是postgres的新手,我正在尝试创建一个查询,以确定从今天开始的6个月之前的哪个月。 另外,我想用西班牙语显示这个月的名字。
例如:今天的月份是“五月”,六个月前是“十一月”,所以我想用西班牙语'Noviembre'显示这个月的名字。
这就是我尝试这样做但它只显示空行:
select
(
case
when to_char(current_date-interval '6 Month','Month')='January' then 'Enero'
when to_char(current_date-interval '6 Month','Month')='February' then 'Febrero'
when to_char(current_date-interval '6 Month','Month')='March' then 'Marzo'
when to_char(current_date-interval '6 Month','Month')='April' then 'Abril'
when to_char(current_date-interval '6 Month','Month')='May' then 'May'
when to_char(current_date-interval '6 Month','Month')='June' then 'Junio'
when to_char(current_date-interval '6 Month','Month')='July' then 'Junio'
when to_char(current_date-interval '6 Month','Month')='August' then 'Agosto'
when to_char(current_date-interval '6 Month','Month')='September' then 'Septiembre'
when to_char(current_date-interval '6 Month','Month')='October' then 'Octubre'
when to_char(current_date-interval '6 Month','Month')='November' then 'Noviembre'
when to_char(current_date-interval '6 Month','Month')='December' then 'Diciembre'
end
) as "Hace 6 Meses"
from "recibopagoderechoslaborales";
答案 0 :(得分:2)
您只需为您的客户调整lc_time
:
so=# set lc_time = 'es_ES';
SET
so=# select to_char(now() - '6 month'::interval,'TMMonth');
to_char
-----------
Noviembre
(1 row)
未对其进行本地化:
so=# set lc_time to default ;
SET
so=# select to_char(now() - '6 month'::interval,'TMMonth');
to_char
----------
November
(1 row)