2
device_id device_created_at
10e7983e-6a7b-443f-b0fe-d5e6485a502c 2022-08-10 20:55:16.695

i have a table where my date/time is of form: 2022-08-10 20:55:16.695 This is a timestampped object. I tried the following query but didn't return any rows:

select * from device where to_char(device_created_at,'YYYY-MM-DD HH24:MI:SS.FFF') = '2022-08-10 20:55:16.695'

The type of device_created_at is "timestamp without time zone"

How do i query based on timestamp in postgressql?

1 Answer 1

2

Try comparing timestamp values in place of strings:

SELECT * 
FROM device 
WHERE device_created_at = CAST('2022-08-10 20:55:16.695' AS TIMESTAMP)

Check the demo here.

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

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.