• 问题
  • 把结果扩展一下
  • 问题

    最近有个需求,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会报,其他语句也会报这个错。原因都是类型不符,只要抓住这个,去排错就行了。

    后台报错 ERROR: syntax error at end of input 数据库报错 :invalid input syntax for type numeric: "未审核"

    问题:如标题所示 需求: (case state when 0 then '未审核' when 1 then '审核通过' when -1 then '审核不通过' else state end) state_name state是数值类型的,pgsql中这么写是不允许的 ,有数值类型转为'未审核' ...

    SpringBoot:ERROR: column “***“ is of type numeric but expression is of type character varying

    问题SpringBoot:在postgresql数据库提交数据时,出现ERROR: column "***" is of type numeric but expression is of type ch