简体   繁体   中英

How to query by time in postgresql

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM