php - extract month function not working in postgres

I have the table test and want to extract the month from the field month which is character varying.

distinct month Field value as 'August-2020','September-2020'

I have tried as SELECT extract(Month from to_date(t.month, '%Month-%YYYY')) as test FROM test as t but getting the error invalid value "ugust-2020" for "MONTH" DETAIL: The given value did not match any of the allowed values for this field.

I have two server in one server working fine as extracting (8,8,9,9) but in another server getting error.

Answer

Solution:

Your format mask is wrong and you should be using:

Month-YYYY

Sample query:

SELECT EXTRACT(month FROM TO_DATE(t.month, 'Month-YYYY')) AS month
FROM test t;

Source