• pgsql case when 报错: ERROR: invalid input syntax for type numeric ,应该如何处理?


    文章目录

    问题

          最近有个需求,sql如下:

    select 
    	case 
    		when score < 60  then  60  
    		else '优秀' end  
    from stuent
    

         但是运行的时候报错了:ERROR: invalid input syntax for type numeric:'优秀'
          百度说:数据类型不符。
          仔细想一下, 60是int,优秀是string,确实类型不符。
          sql修改如下:

    select 
    	case 
    		when score < 60  then '' || 60  
    		else '优秀' end  
    from stuent
    

      这样就都是string了,就不报错了。

    把结果扩展一下

          其实这个报错不只case when会报,其他语句也会报这个错。原因都是类型不符,只要抓住这个,去排错就行了。

  • 相关阅读:
    Lucene综合案例
    Lucene 高级搜索
    Lucene 分词器
    Lucene 索引维护
    Lucene Field域类型
    Lucene入门
    Lucene介绍和全文检索流程
    数据查询方法
    序列化
    drf
  • 原文地址:https://www.cnblogs.com/shui68home/p/15483498.html
Copyright © 2020-2023  润新知