Postgresql 搜索早于阈值的项目


Postgresql search for items older than a threshold

似乎这应该是一件简单的事情,但是postgresql中的日期/时间操作正在杀死我。 我要做的只是搜索超过 10 分钟的项目。 编码语言是PHP。

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

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

此查询返回所有结果,而不是超过 10 分钟的项目。 我需要以某种方式键入该event_time字段吗?

通过使用负阈值,您有一个双重否定,因此您将搜索未来不到十分钟的所有内容(这自然会返回所有内容)。只需使用interval '{$threshold} minutes}'