gpt4 book ai didi

sql - 错误 : operator does not exist: character varying = boolean

转载 作者:行者123 更新时间:2023-11-29 12:40:39 28 4
gpt4 key购买 nike

我有以下查询:

SELECT
CASE
tbl_appointment_types."name"
WHEN tbl_appointment_types."name" LIKE 'Refill-ART' THEN
'Re-Fill'
WHEN tbl_appointment_types."name" = 'Enhanced Adherence'::character varying THEN
'Enhanced Adherence'
WHEN tbl_appointment_types."name" = 'PHARMACY APPOINTMENT'::character varying THEN
'Re-Fill' ELSE tbl_appointment_types."name"
END
FROM
tbl_appointment INNER JOIN tbl_appointment_types ON tbl_appointment_types."id" = tbl_appointment.app_type_1
GROUP BY
tbl_appointment_types."name";

当我尝试运行它时,出现以下错误:

> ERROR:  operator does not exist: character varying = boolean
LINE 4: WHEN tbl_appointment_types."name" LIKE 'Refill-ART' THEN
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

> Time: 0.054s

如何解决以下问题?

最佳答案

CASE 表达式有两种形式:

一种“简短”形式,仅支持相等性,您首先声明表达式,然后声明应与之比较的值(使用 =),例如

 CASE some_column
WHEN 1 THEN 'One'
WHEN 2 THEN 'Two'
ELSE 'Something else'
END

或者更详细的版本,您可以为每个 WHEN 使用不同的条件。但在那种情况下,您可以在 CASE 之后使用表达式:

 CASE -- nothing here!
WHEN some_column = 1 THEN 'One'
WHEN some_column = 2 THEN 'Two'
ELSE 'Something else'
END

因此您需要将 CASE 表达式写为:

CASE -- nothing here!
WHEN tbl_appointment_types."name" LIKE 'Refill-ART' THEN 'Re-Fill'
WHEN tbl_appointment_types."name" = 'Enhanced Adherence' THEN 'Enhanced Adherence'
WHEN tbl_appointment_types."name" = 'PHARMACY APPOINTMENT' THEN 'Re-Fill'
ELSE tbl_appointment_types."name"
END

使用不带通配符的 LIKE 没有任何意义。 "name"LIKE 'Refill-ART'"name"= 'Refill-ART' 相同。

您的意思可能是 "name"LIKE 'Refill-ART%'(注意末尾的 %)

关于sql - 错误 : operator does not exist: character varying = boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52186086/

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