英文:
How to query by time in postgresql
问题
以下是翻译好的内容:
device_id | device_created_at | |
---|---|---|
10e7983e-6a7b-443f-b0fe-d5e6485a502c | 2022-08-10 20:55:16.695 | Three |
我有一个表格,其中我的日期/时间的格式为:2022-08-10 20:55:16.695,这是一个时间戳对象。我尝试了以下查询,但没有返回任何行:
select * from device where to_char(device_created_at,'YYYY-MM-DD HH24:MI:SS.FFF') = '2022-08-10 20:55:16.695'
device_created_at 的类型是 "timestamp without time zone"。
如何在 PostgreSQL 中基于时间戳进行查询?
英文:
device_id | device_created_at | |
---|---|---|
10e7983e-6a7b-443f-b0fe-d5e6485a502c | 2022-08-10 20:55:16.695 | Three |
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
得分: 2
尝试使用时间戳值而不是字符串进行比较:
SELECT *
FROM device
WHERE device_created_at = CAST('2022-08-10 20:55:16.695' AS TIMESTAMP)
在此处查看演示:链接。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论