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?
CodePudding user response:
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.