19:51 Friday, October 10 2007

racks + SQL

I finally finished building & deploying all the server racks today. I now have 6 racks in the lab.
In other news, started working on a new project at work this afternoon. One of the key parts of it requires me to run a SQL query which would return the rows that were inserted since 4PM. The best I could figure out only worked correctly if it was run between midnight & 4PM. I ended up turning to the every helpful pgsql-novice mailing list, and got this excellent solution (date_createad is the column name in my table, and is just a date/timestamp):

select count(date_created) from footable0
where case when current_time \< '16:00'::time
then date_created between (current_date - 1) + interval '16 hours'
and current_date + interval '16 hours'
else date_created between current_date + interval '16 hours'
and (current_date + 1) + interval '16 hours'
end;