I have a list of timestamped logs and I'd like a query to return 12 booleans say whether a certain month contains any logs, for each month of the year (starting from January), i.e.:
(True, False, False, True, False ..., True)
I currently have the following query, which will show me all months containing data:
SELECT DISTINCT(EXTRACT(MONTH FROM logdate)) AS month
FROM mytable
WHERE EXTRACT(YEAR FROM logdate) = '2009'
ORDER BY month;
The output of which is a list of months containing data, e.g.:
(1, 2, 5, 6, 12)
I just can't work out the next step - any pointers would be appreciated.
I am using PostgreSQL v8.4.2. Thanks.