Home > Software engineering >  Is there a way to return all non-null values even if one is null in PostgreSQL?
Is there a way to return all non-null values even if one is null in PostgreSQL?

Time:08-04

The statement I've got is

select coalesce(A||','||B||','||C) into D

If C is null, then D will = < NULL >, but if I remove C and just have A and B, then D will = the values of A & B. There may be situations where any one of those is NULL and I still want to return any non-null values into D - is this possible? Thanks!

CodePudding user response:

Use concat_ws() instead:

select concat_ws(',', a, b, c)
  • Related