0

I'm using this to try and get all events with a timestamp of today

SELECT systemuserid,ondate from auditlog 
WHERE ondate::date = NOW()::date

Performance seems really bad, over 2 minutes. I have a index on ondate.

Is there a more efficient way to do it?

Thanks

1 Answer 1

2

Use a range condition:

select *
from auditlog
where ondate >= current_date
  and ondate < current_date + 1;

current_date will be converted to a timestamp at midnight, so ondate => current_date will include everything from "today".

And the condition ondate < current_date + 1 will exclude rows with a timestamp of tomorrow (midnight) or later.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that does it in under a second!

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.