【发布时间】:2020-06-02 17:20:13
【问题描述】:
我有一个名为 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 类型的字符变化和数字无法匹配
【问题讨论】:
-
在传递给
coalesce()之前将两者都转换为字符串。
标签: postgresql coalesce