【发布时间】:2020-07-20 07:37:55
【问题描述】:
SELECT * FROM work_hour where start_time between '2020-04-06 23:03' and '2020-04-09 23:03';
这在将 search_path 设置为 foo 时有效 但是我想使用相同的查询而不是我想使用参数的字符串
所以我在我的服务函数中使用了这个注解:
@Query(value = "SELECT s FROM foo.work_hour s WHERE TO_TIMESTAMP(s.start_time, 'YYYY-MM-DD HH24:mi')\\:\\:timestamp BETWEEN :start_time\\:\\:timestamp AND now()\\:\\:timestamp", nativeQuery = true)
但这似乎行不通。
There was an unexpected error (type=Internal Server Error, status=500). could not execute query; SQL [SELECT s FROM logines.work_hour s WHERE TO_TIMESTAMP(s.start_time, 'YYYY-MM-DD HH24:mi')::timestamp BETWEEN ?::timestamp AND now()::timestamp]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.
如何实现?
【问题讨论】:
-
可能不相关,但是:
to_timestamp()用于将不是时间戳转换为时间戳的内容。在 is 已经是时间戳的列上调用它是完全错误的。我认为你应该用简单的:start_time替换:start_time\\:\\:timestamp,然后传递java.time.LocalDateTime的实例作为参数(或至少java.sql.Timestamp)。 -
您是否尝试过实际搜索错误消息的含义?
标签: postgresql spring-boot jpa