Reputation: 512
Hey everyone. Here is my situation... I need to craft a sql query against a postgresql server that will return all records created within the past 5 minutes, rounded down to the lowest minute. So if cron kicks the query off at 12:05:25.000, it needs to query all records created since 12:00:00.000. So I guess I really have two issues.
I know using
DATE_SUB(now(),INTERVAL 5 MINUTE)
works in mysql - is there an equivalent in postgresql? I couldn't find any mention of it in the date/time functions documentation here.
Second, how do I tell it to round down to the minute (ignore seconds) for the 5 minute interval?
Any advice would be appreciated.
Upvotes: 3
Views: 4731
Reputation: 95562
select current_timestamp - interval '5' minute
And to eliminate the seconds
select current_timestamp - interval '5' minute -
(extract(seconds from current_timestamp) || 'seconds')::interval
Upvotes: 8