gpt4 book ai didi

postgresql - COALESCE 类型字符变化和数字不能匹配

转载 作者:行者123 更新时间:2023-12-04 12:38:17 30 4
gpt4 key购买 nike

我有一张名为 table1 的表带列Gender varchar(10)Team numeric .

create table table1 (
ID integer
Gender varchar(10),
Team numeric
);

insert into table1 (ID,Gender,Team) values
(1,'M',NULL),
(2,NULL,10),
(3,NULL,6),
(4,''F',NULL),
(5,NULL,3);

我想创建一个新专栏 Nxt从字符串或整数的任何列返回不为空的行。

栏目 Nxt看起来像: M,10,6,F,3
我试过这个:
select coalesce(Gender,Team) as value from table1;

它返回此错误:

COALESCE types character varying and numeric cannot be matched

最佳答案

尝试将列转换为文本

    select coalesce(Gender,Team::text) as value from table1;

关于postgresql - COALESCE 类型字符变化和数字不能匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62157668/

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