Change PostgreSQL date language from request

谁说胖子不能爱 提交于 2019-12-24 04:40:50

问题


I'm kind of new to PostgreSQL and I'm trying to change the locale of the date function results, to get the result of to_char(my_date, 'Month') in another language.

Here are some of my settings :

$> show lc_time;

en_US.UTF-8

I found in the documentation that the locale could be changed at the database initialization :

initdb --locale=fr_FR

But that's not exactly what I'm looking for.

In MySQL, I used to do it like :

SET lc_time_names = 'fr_FR';

But unfortunately, I can't find a way to do it with PostgreSQL. Is there any ?


回答1:


You can get the localized version of the name of the month with the special TM format (translation mode):

to_char(my_date, 'TMMonth')

You can also apply this to the names of the weekdays with TMD. Both versions will display the names using the locale of the server, unless the lc_time run-time parameter has a specific setting. That setting can also be changed for the current session:

SET lc_time = 'fr_FR';

When you want to revert back to the default setting in the same session, use:

SET lc_time TO DEFAULT;


来源:https://stackoverflow.com/questions/33009076/change-postgresql-date-language-from-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!