1

I'm using Postgres 9.1 and try to get records from a table knowing the given month and should know if the date type date field contains the month.

This is my query:

SELECT consejo.numero,consejo.fecha FROM consejo WHERE MONTH(consejo.fecha) = 2

but I get the following error:

ERROR: There is no month function (date)
LINE 1: ... T consejo.numero, consejo.fecha council FROM WHERE MONTH (cons ...

HINT: No function matches the name and types of arguments. You may need to add explicit type conversion.

might be wrong?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
user1813375
  • 101
  • 2
  • 12

2 Answers2

3

In Postgresql there is no MONTH function available. You can use EXTRACT instead:

WHERE EXTRACT(MONTH FROM consejo.fecha) = 2
Giorgos Betsos
  • 69,699
  • 7
  • 57
  • 89
0

Another option is to use PostgreSQL's date_part() function:

 WHERE date_part('month', consejo.fecha) = 2

Look at the reference guide:

http://www.postgresql.org/docs/9.5/static/functions-datetime.html

Rodrigo Hjort
  • 191
  • 2
  • 5