Lewisj
Lewisj

Reputation: 41

Coalesce and Concat in the same statement, Postgres

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)

Upvotes: 4

Views: 5100

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270011

Just use the concatenation operator, ||:

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

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

Upvotes: 6

Related Questions