Home > front end >  Can I only select the values if it is not null?
Can I only select the values if it is not null?

Time:08-05

I've got values stored in variables that I only want inserted if it doesn't return null - possible to do this with SQL? I've tried the below:

select (A, B, C, D, E) into variable1 where concat_ws(A, B, C, D, E) is not null;
select variable1 into variable2;

So I think it's still returning (A, null, C, D, null) into variable2 where ideally I'd like it just to return (A, C, D) into variable2 instead. (Have also tried with concat, coalesce). Thanks!

CodePudding user response:

I do not know about the selection into variables, but this should do what you ask if A through E are columns:

select array_to_string(array_remove(array[a, b, c, d, e], null), ',') as variable1
  from testme;

db<>fiddle here

  • Related