Months in portuguese

Hi!
I'm trying to show in my dynamic table the date information with this format: month year (example: Janeiro 2021). So, I want the month in portuguese.
The original format is that (with the non needed day and hour):

mm_pt
To get this result, I'm using:

date_trunc ('month', mês) AS mês,

When I try to extract only the month and year information, I get the result in english:

mm_en
To get this result I used:

 to_char(mês, 'month YYYY') AS mês

 to_char(date_trunc('month', mês), 'month YYYY') AS mês

Can I get this information the way I want it?

I'm sure this has to be about locales, have you seen https://www.postgresql.org/docs/9.6/functions-formatting.html?

Yes, I already read it. But I could not get the months in portuguese, only in english :confused:

try

to_char(date_trunc('month', mês), 'TMmonth YYYY') AS mês

got answer from https://stackoverflow.com/questions/54872022/postgresql-to-char-ignores-locale

which seems to be from " Table 9-25. Template Pattern Modifiers for Date/Time Formatting" in https://www.postgresql.org/docs/9.6/functions-formatting.html

It did not work:

Capturar

@Helena Try TMMonth or set the lc_time in the connection string - sounds like your database is probably created with English as the default.
Read everything here: https://www.postgresql.org/docs/current/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIMEMOD-TABLE

Hi, @flamber! TMMonth did not work... and I tried lc_time but got this message:

ERROR: permission denied to set parameter "lc_time" to "pt_BR.UTF8"

I've tried this:

SET lc_time TO 'pt_BR.UTF8';
SELECT 
(...)

@Helena Well, you would need to talk to your database administrator, so they can help you setting the correct language.

I have the administrator profile and searching the settings, I found the following:

idioma

Do I need to configure another setting?

@Helena You are using SQL, so the Metabase instance does not apply here. You need to contact your database administrator, since you are getting a permission error from the database.

1 Like

Hmmmmmm... ok! I'm talking to him now. Thank you!

You need to enable your language in Metabase Postgres server.

  1. Edit your /etc/locale.gen and uncomment your language
  2. Run locale-gen command
  3. Ensure locale alias with this command:
localedef -i es_ES -c -f UTF-8 -A /usr/share/locale/locale.alias es_ES.UTF-8 
  1. Set default Postgres lc_time value in /etc/postgresql/XX/main/postgresql.conf (By default is C.UTF-8, replace it using your language code alias)
  2. Restart Postgres service
  3. Test it in psql command interface
SELECT TO_CHAR('2022-01-01'::Date, 'TMmonth');

Output

 to_char 
---------
 enero
(1 row)

Enjoy.