2014-09-10 2 views
2

"를 텍스트로 알 수없는에서 변환 기능을 찾지 못했습니다"나는 다음 PostgreSQL의 쿼리를 가지고 :PostgreSQL을 오류 :

내가이 쿼리를 실행하려고
with A as 
    (
      select '201405MASE04' as TestID, Count(*) TotQ, Count(distinct Case When SE1 = '' then NULL else SE1 end) TotSE, 
       case when Count(*)=0 then 7 else Count(distinct RC) end TotRC 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Omit <> 1 
    ), 
    B as 
    (
      select '201405MASE04' as TestID, Count(*) TotQ 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Omit = 1 
    ), 
    C as 
    (
      select '201405MASE04' as TestID, Count(*) TotQ 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Question_Type_ID='2' 
    ) 

    Select A.TestID, A.TotQ + coalesce(B.TotQ,0) - coalesce(C.TotQ,0) as TotQ, A.TotSE, A.TotRC 
    From A 
    left outer Join B on A.TestID = B.TestID 
    left outer Join C on A.TestID = C.TestID 

, 그것은 나에게 다음과 같은 오류를 던지고있다 :

ERROR: failed to find conversion function from unknown to text 

********** Error ********** 

ERROR: failed to find conversion function from unknown to text 
SQL state: XX000 

여기서 어떻게 변환 오류가 발생하는지 어떻게 알 수 있습니까?

답변

3

postgres가 상수 '201405MASE04'을 좋아하지 않는 것 같습니다.

SQL Fiddle Demo 같은 오류가 발생합니다.

SQL Fiddle Demo 데이터 형식이이 문제를 해결하는 캐스트를 보여줍니다.

시도해보십시오. 텍스트로 정의합니다.

with A as 
    (
      select cast('201405MASE04' as text) as TestID, Count(*) TotQ, Count(distinct Case When SE1 = '' then NULL else SE1 end) TotSE, 
       case when Count(*)=0 then 7 else Count(distinct RC) end TotRC 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Omit <> 1 
    ), 
    B as 
    (
      select cast('201405MASE04' as text) as TestID, Count(*) TotQ 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Omit = 1 
    ), 
    C as 
    (
      select cast('201405MASE04' as text) as TestID, Count(*) TotQ 
      from eivTestItems TI, eivTests T 
      where TI.Test_ID = T.Test_ID 
       and T.Test_Type_ID = 1 
       and T.Test_ID= '201405MASE04' 
       and TI.Question_Type_ID='2' 
    ) 

    Select A.TestID, A.TotQ + coalesce(B.TotQ,0) - coalesce(C.TotQ,0) as TotQ, A.TotSE, A.TotRC 
    From A 
    left outer Join B on A.TestID = B.TestID 
    left outer Join C on A.TestID = C.TestID 
+0

멋진 고마워요. – Abhishek