CASE类型整数和文本无法匹配Postgres

时间:2017-08-18 07:00:06

标签: postgresql case

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是文字

1 个答案:

答案 0 :(得分:0)

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;

这解决了我的错误