I am trying to pull some data from a Postgres database to implement a birthday reminder system, but I am having a little trouble in getting my query to work. Basically, I want to pull all of the records whose birthday field falls within a certain one-month span. I have tried the following query:
SELECT *
ALL persons
WHERE EXTRACT(MONTH from birthday) >= 9
AND EXTRACT(DAY from birthday) >= 15
INTERSECT
SELECT *
ALL persons
WHERE EXTRACT(MONTH from birthday) <= 10
AND EXTRACT(DAY from birthday) <= 15
The first portion of the query (before the INTERSECT) seems to be working as I would like, but the second portion is excluding dates in any month before the 15th. For instance, if there was a birthday on 9/20, the first portion would include it but the second portion would exclude it since it is after the 15th day (even though it still falls before 10/15). Any ideas how to remedy this?
This should work:
edit: bug fixed