Matthew
Matthew

Reputation: 512

PostgreSQL query - return all results with field with past 5 minutes

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.

Any advice would be appreciated.

Upvotes: 3

Views: 4731

Answers (1)

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

Related Questions