Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A common grouping needed by sysadmins is to group by 5 minute intervals. That query may be more likely to trip up a junior DBA than most of these. Could be useful to add.

Example use case: http://www.techtalkz.com/microsoft-sql-server/170861-groupin...



Do you happen to know the most elegant solution to this problem?

Convert the date to seconds since date X (or unix timestamp / 60) and divide by the number of mins you need and convert to int.


Never use raw numbers to represent slices of time, there's just too many corner cases that can throw your calculations off.

Use the INTERVAL data type, it handles the logic properly.


Postgres has `EXTRACT(EPOCH FROM date_col)`, which might not be where you'd think to find that functionality.


Good suggestion!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: