在同一声明中,Coalcece和Concat,Postgres [英] Coalesce and Concat in the same statement, Postgres

查看:101
本文介绍了在同一声明中,Coalcece和Concat,Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图同时合并一个人的名字和姓氏,但是当值为空时合并一个队名。不幸的是,我的语法返回了SPACE,因此合并不会将其识别为空值。

I am trying to concat an individual's first and last name together but coalesce a team name when there is a null value. Unfortunately my syntax is returning a SPACE, so coalesce does not recognize it as a null value.. What can I do to correct this?

语法我目前正在使用:

coalesce((Concat(first_name,' ',last_name)),team_name)


推荐答案

只需使用串联运算符 ||

coalesce(first_name || ' ' || last_name, team_name)

concat()函数将忽略 NULL 值。运算符返回 NULL

The concat() function ignores NULL values. The operator returns NULL.

这篇关于在同一声明中,Coalcece和Concat,Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆