Selecting by month in PostgreSQL

SqlPostgresqlDate

Sql Problem Overview


I want to select rows according to the month of a date or timestamp column like this:

SELECT id, name, birthday 
FROM employee.person 
WHERE Month(birthday) > 10;

But I only get error messages in PostgreSQL.
How can this be done?

Sql Solutions


Solution 1 - Sql

You can use EXTRACT function, like this:

SELECT id, name, birthday FROM employee.person 
WHERE EXTRACT(MONTH FROM birthday) > 10;

Your problem comes from the fact that there is no such thing as Month function in PostgreSQL. Check online documentation here to see what you can get instead. Extract should be enough.

Solution 2 - Sql

If you want you can also extract the month name using the following function.

SELECT TO_CHAR(DATE(REPORT_DATE), 'Month') FROM TABLE_NAME

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionauliaView Question on Stackoverflow
Solution 1 - Sqlk.mView Answer on Stackoverflow
Solution 2 - SqlAnish JainView Answer on Stackoverflow