I have to admit, I'm puzzled by your double layer query - shown after "The following query times out"
My impression is that you could just do the following (and as it's not my familiar dialect, I had to check that PostgreSQL supports both CURRENT_DATE and DISTINCT ).
As you have limited the date span to the last 7 days, there is no particular need to derive what days of the week those are, as each date will be a different one anyway.
Admittedly this begs the question of which data interpretation you'd want for a longer date span, say over two weeks - i.e. whether you would want "different days" or "different days of the week".
p.s. it's cute that you've quoted the Ruby classes but it means nothing to those of us who work in SQL. I've assumed that created_at is a date column for display simplicity, but if it's a timestamp then some additional wrapping will be necessary (probably just a CAST to DATE).
Recovering interrupter with occasional relapses, lover of spreadsheets, blogger, programmer, adept debugger, conjurer of analogies, and probably other things.
Recovering interrupter with occasional relapses, lover of spreadsheets, blogger, programmer, adept debugger, conjurer of analogies, and probably other things.
I have to admit, I'm puzzled by your double layer query - shown after "The following query times out"
My impression is that you could just do the following (and as it's not my familiar dialect, I had to check that PostgreSQL supports both CURRENT_DATE and DISTINCT ).
As you have limited the date span to the last 7 days, there is no particular need to derive what days of the week those are, as each date will be a different one anyway.
Admittedly this begs the question of which data interpretation you'd want for a longer date span, say over two weeks - i.e. whether you would want "different days" or "different days of the week".
p.s. it's cute that you've quoted the Ruby classes but it means nothing to those of us who work in SQL. I've assumed that
created_at
is a date column for display simplicity, but if it's a timestamp then some additional wrapping will be necessary (probably just a CAST to DATE).I also think I had an off by one error in my query that your fix updates. So a double thank you.
I tried the following and it appears to get me the answer:
So thank you for helping me further simplify this thing.
The created_at, as a Ruby on Rails idiom is a timestamp.
I included the Ruby as it's reasonably accessible from a description (though I could make it easier).