PostgreSQL - Enforcing unique constraint on date column parts
Using EXTRACT(year/month ...) works, too:

create unique index year_month_uq 
  on foo 
  ( extract(year from mydate), 
    extract(month from mydate)
  ) ;