Coalesce and Concat in the same statement, Postgres

人走茶凉 提交于 2019-12-01 22:31:19

问题


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?

Syntax I am currently using:

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

回答1:


Just use the concatenation operator, ||:

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

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



来源:https://stackoverflow.com/questions/41770098/coalesce-and-concat-in-the-same-statement-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!