nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

报的错误:

2018-08-02 10:14:55.070  WARN 1744 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42883
2018-08-02 10:14:55.070 ERROR 1744 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: function time_bucket(character varying, timestamp with time zone) does not exist
  建议:No function matches the given name and argument types. You might need to add explicit type casts.
  位置:10
2018-08-02 10:14:55.220 ERROR 1744 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: function time_bucket(character varying, timestamp with time zone) does not exist
  建议:No function matches the given name and argument types. You might need to add explicit type casts.
  位置:10

报错的原因:

 @Query(value = "SELECT time_bucket(?1, time) AS bucket, avg(value) AS avg_value FROM metrics WHERE tag=?2 and time between ?3 AND ?4 GROUP BY bucket ORDER BY bucket DESC" ,nativeQuery = true)
   List selectTimeBucket(String timeBucket,String tag ,Timestamp startTime , Timestamp endTime);
@RequestMapping(value = "/selectTimeBucket" )
public List selectTimeBucket(@RequestParam("timeBucket") String timeBucket, @RequestParam("tag") String tag ,
                       @RequestParam("startTime") Timestamp startTime ,@RequestParam("endTime") Timestamp endTime){
    return metricsRepository.selectTimeBucket(timeBucket,tag,startTime,endTime);
}

地址输出:

http://127.0.0.1:8080/selectTimeBucket?timeBucket=1%20hour&tag=AAA&startTime=2018-7-01%2011:00:00&endTime=2018-7-26%2011:00:00

如果改成:

 @Query(value = "SELECT time_bucket('1 hour', time) AS bucket, avg(value) AS avg_value FROM metrics WHERE tag=?1 and time between ?2 AND ?3 GROUP BY bucket ORDER BY bucket DESC" ,nativeQuery = true)
   List selectTimeBucket(String tag ,Timestamp startTime , Timestamp endTime);

就可以运行出结果!!

官网:https://docs.timescale.com/v0.10/using-timescaledb/reading-data#select

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值