Conditionally insert a value in an array when creating a new column I have some data in a jsonb col that I need to clean and insert into another text array column.
What I have:
[
  {
    &quot;v&quot;: &quot;birthday&quot;
  },
  {
    &quot;v&quot;: &quot;reference&quot;
  }
]

What I want (_text):
{birthday, reference}

My query:
select array[col -&gt; 0 -&gt;&gt; 'v', col-&gt; 1 -&gt;&gt; 'v'] from src

gives the expected result as above.
However, when the value is null, I want the value not to be inserted i.e. no NULL value nor empty:
[
  {
    &quot;v&quot;: &quot;birthday&quot;
  }
]

should result in
{birthday}

and not
{birthday, [NULL]} -- NULL value
{birthday,} -- Empty string with coalesce

How do you conditionally insert an element into an array when creating one, based on the value of the element?
array_remove() seems to answer my use case (by removing in a 2nd step the null values):
select array_remove(array[col -&gt; 0 -&gt;&gt; 'v', col-&gt; 1 -&gt;&gt; 'v'], null) from src