gpt4 book ai didi

sql - PostgreSQL 错误 : "failed to find conversion function from unknown to text"

转载 作者:行者123 更新时间:2023-11-29 11:43:18 26 4
gpt4 key购买 nike

我有以下 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

我如何找出此处出现转换错误的位置?

最佳答案

看起来 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

关于sql - PostgreSQL 错误 : "failed to find conversion function from unknown to text",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25770528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com