1

I'm trying to write a query that uses postgres. My query needs to find the diffrence between the started_at time and now() and then only select the data where the difference is >= 300 seconds.

Here is what I have so far

SELECT id, (extract(epoch from now()) - extract(epoch from started_at)) completed_time
FROM run_item WHERE started_at IS NOT NULL AND completed_at is NULL;

2 Answers 2

1

Have you tried placing this expression the where clause?

SELECT * FROM run_item WHERE
(EXTRACT(EPOCH FROM now()) - EXTRACT(EPOCH FROM started_at)) >= 300;
Sign up to request clarification or add additional context in comments.

Comments

1

find the diffrence between the started_at time and now() and then only select the data where the difference is >= 300 seconds

You could do date arithmetics as follows:

select id, started_at - now() diff
from run_item r
where started_at <= now() - interval '5' minutes

In the resultset, diff is a column of interval datatype.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.