gpt4 book ai didi

sql - 错误 : CASE types character varying and numeric cannot be matched

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

我在 Postgres 中写了一个 select 语句,其中包含如下 case 语句:

,(case when all_loc.country = 'DE' then msc_si.buyer_id else msc_si.buyer_name end) as "purchasing_group_name_buyer_name"  --story
,(case when all_loc.country = 'DE' then msc_si.planner_code else mscp.description end) as "mrp_controller_name" --story

我收到以下错误。我尝试使用 IS 而不是 =,但没有用。如果没有这两个 case 语句,查询将完美运行。

ERROR: CASE types character varying and numeric cannot be matched SQL state: 42804

最佳答案

case 表达式的所有分支都应该返回相同的数据类型。实现这一目标的一种方法是在需要的地方显式转换:

,(case when all_loc.country = 'DE' then msc_si.buyer_id::varchar else msc_si.buyer_name end) as "purchasing_group_name_buyer_name"
-- Here -----------------------------------------------^
,(case when all_loc.country = 'DE' then msc_si.planner_code::varchar else mscp.description end) as "mrp_controller_name"
-- And here -----------------------------------------------^

关于sql - 错误 : CASE types character varying and numeric cannot be matched,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44317657/

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