【问题标题】:CASE types integer and text cannot be matched PostgresCASE 类型整数和文本无法匹配 Postgres
【发布时间】:2017-08-18 19:20:10
【问题描述】:
DECLARE
        pop  character varying;
    BEGIN
       EXECUTE 'SELECT CASE(select EXISTS(select count(case_reported) from qwe where week = '' weekk  '' and code = ''  codee ''  and case_type= '' case_type '' HAVING count(case_reported) > 0 ) )  
        WHEN TRUE
              THEN (select CASE(count(case_reported)) 
                        WHEN 1
                             THEN 
                                 (select CASE(case_reported)
                                       WHEN 1
                                             THEN 1::varchar
                                       WHEN 0
                                             THEN ''zr''::varchar
                                       END
                                 from qwe where week = '' weekk  '' and code = '' codee '' and case_type= '' case_type '')
                             ELSE 
                                 count(case_reported)::TEXT 
                        END 
                    from qwe where week = '' weekk  '' and code = '' codee '' and case_type= '' case_type '')     
              ELSE 0 END' into pop;
    RETURN pop;
    END;

错误:CASE 类型整数和文本无法匹配。

pop,week,code 是字符类型,case_type 是文本

【问题讨论】:

    标签: postgresql case


    【解决方案1】:
    DECLARE
            pop  character varying;
        BEGIN
           EXECUTE 'SELECT CASE(select EXISTS(select count(case_reported) from qwe where week = '' weekk  '' and code = ''  codee ''  and case_type= '' case_type '' HAVING count(case_reported) > 0 ) )  
            WHEN TRUE
                  THEN (select CASE(count(case_reported)) 
                            WHEN 1
                                 THEN 
                                     (select CASE(case_reported)
                                           WHEN 1
                                                 THEN 1::TEXT
                                           WHEN 0
                                                 THEN ''zr''::TEXt
                                           END
                                     from qwe where week = '' weekk  '' and code = '' codee '' and case_type= '' case_type '')
                                 ELSE 
                                     count(case_reported)::TEXT 
                            END 
                        from qwe where week = '' weekk  '' and code = '' codee '' and case_type= '' case_type '')     
                  ELSE 0::TEXT END' into pop;
        RETURN pop;
        END;
    

    这解决了我的错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      相关资源
      最近更新 更多