带时间戳的Java Spring/PgSQL操作返回间隔

带时间戳的Java Spring/PgSQL操作返回间隔,java,spring,postgresql,spring-boot,spring-mvc,Java,Spring,Postgresql,Spring Boot,Spring Mvc,我试图使用Postgresql数据库在JavaSpring上检索时间戳间隔内的数据。 我使用的其中一个查询工作正常(它返回过去24小时的数据): 我无法理解的是,根据PostgreSQL文档,一个时间戳间隔应该返回另一个时间戳。然而,从我的查询来看,我似乎将时间戳(从表中)与间隔进行比较,这是错误的。如果我尝试直接使用timestamp参数(以timestamp>的形式:timestamp而不减少间隔),它可以工作,但不是我想要的 通过使用:timestamp::timestamp我也尝试过显式

我试图使用Postgresql数据库在JavaSpring上检索时间戳间隔内的数据。 我使用的其中一个查询工作正常(它返回过去24小时的数据):

我无法理解的是,根据PostgreSQL文档,一个时间戳间隔应该返回另一个时间戳。然而,从我的查询来看,我似乎将时间戳(从表中)与间隔进行比较,这是错误的。如果我尝试直接使用timestamp参数(以timestamp>的形式:timestamp而不减少间隔),它可以工作,但不是我想要的


通过使用:timestamp::timestamp我也尝试过显式强制转换,但由于Spring及其处理参数的方式,这似乎会产生另一种错误。

您可能希望尝试将参数显式强制转换为
时间戳

where 
    sigla_impianto = :impianto 
    and timestamp > :timestamp::timestamp - interval '24 hours'
或者,可能:

where 
    sigla_impianto = :impianto 
    and timestamp > cast(:timestamp as timestamp) - interval '24 hours'

谢谢你的回答。正如我在我的问题上所说的,出于某种原因,这似乎不起作用,因为我得到了一个java.lang.IllegalArgumentException:找不到命名参数[timestamp],需要[impianto,timestamp::timestamp]@Mastarius:我在我的答案中添加了另一个语法。谢谢,这个替代的显式强制转换方法似乎解决了这个问题
org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone > interval
No operator matches the given name and argument types. You might need to add explicit type casts.
where 
    sigla_impianto = :impianto 
    and timestamp > :timestamp::timestamp - interval '24 hours'
where 
    sigla_impianto = :impianto 
    and timestamp > cast(:timestamp as timestamp) - interval '24 hours'