多重错误:operator does not exist: character varying = bytea

在进行多点查询的时候报错 : postgresql 数据库 ,idea ,SpringBoot ,restful 接口

@Query(value = "  SELECT time_bucket('1 hour', source_time) AS bucket, 
                 avg(value) AS avg_value , count(value) as count_value" +
               " FROM 表名 WHERE tag in(?1) and  source_time " +
               " between ?2 AND ?3 GROUP BY bucket ORDER BY bucket DESC" ,
                nativeQuery = true)
List select1(String[] tag ,Timestamp startTime , Timestamp endTime );

@GetMapping("/select1")
public  List select1(@RequestParam("tag") String[] tag ,
                     @RequestParam("startTime") Timestamp startTime ,
                     @RequestParam("endTime") Timestamp endTime){
    return metricsRepository.selectMoreTimeDay(tag,startTime,endTime);
}

2018-08-17 10:56:48.721  WARN 9116 --- [nio-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42883
2018-08-17 10:56:48.721 ERROR 9116 --- [nio-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: operator does not exist: character varying = bytea
  建议:No operator matches the given name and argument type(s). You might need to add explicit type casts.
  位置:133
2018-08-17 10:56:48.725 ERROR 9116 --- [nio-8082-exec-1] 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: operator does not exist: character varying = bytea
  建议:No operator matches the given name and argument type(s). You might need to add explicit type casts.
  位置:133

 原因:

是要做一个转化类型

@Query(value = "  SELECT time_bucket('1 hour', source_time) AS bucket, 
                 avg(value) AS avg_value , count(value) as count_value" +
               " FROM 表名 WHERE tag in(?1) and  source_time " +
               " between ?2 AND ?3 GROUP BY bucket ORDER BY bucket DESC" ,
                nativeQuery = true)
List select1(List<String> tag ,Timestamp startTime , Timestamp endTime );

@GetMapping("/select1")
public  List select1(@RequestParam("tag") String[] tag ,
                     @RequestParam("startTime") Timestamp startTime ,
                     @RequestParam("endTime") Timestamp endTime){
    //json 字符串转换成java对象数组
        JSONArray json = JSONArray.fromObject(tag);
        List<String> tags = (List<String>)JSONArray.toCollection(json, String.class);
        return metricsRepository.selectMoreTimeDay(tags,startTime,endTime);
}

运行结果,报错 (postmman 做测试)

最终: 

但是前端可以查询到数据。最后自己仔细回想了一下,我自己在controller做了个debug测试一下,前端传给我的数据,其中有一个值是多个的,也就是数组的形式 [ ]。但是我接收到的却是{“[ ]”} 这种类型的,所以用json字符串做了转化。

而我自己做测试的时候,在Chrome直接输入请求的地址,并没有{ } 的产生,所以可以测试到数据。我这里不识别{ } ,原因是Tomcat的问题,在Tomcat 7 的某个版本不支持{ } ,会报错,地址给了大家可以查看!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值