gpt4 book ai didi

php - Postgresql 搜索早于阈值的项目

转载 作者:行者123 更新时间:2023-11-29 12:47:30 25 4
gpt4 key购买 nike

看起来这应该是一件简单的事情,但是 postgresql 中的日期/时间操作让我很烦。我要做的就是搜索超过 10 分钟的项目。编码语言是PHP。

字段 event_time 是:没有时区的时间戳 NOT NULL

$sql = "SELECT * FROM incidents WHERE 
event_time < ( now() - interval '-{$threshold} minutes' )
AND submitted=0 ";

此查询返回所有结果,而不是 10 分钟前的项目。我是否需要以某种方式强制转换该 event_time 字段?

最佳答案

通过使用负阈值,您得到了双重否定,因此您正在搜索 future 不到 10 分钟的所有内容(这自然会返回所有内容)。只需使用 interval '{$threshold} minutes}'

关于php - Postgresql 搜索早于阈值的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11854547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com