0

I have 12 unique IDs in my PostgreSQL 9.5 table for which some array (text) are blanks:

ID(int)     my_array(text)
1           1,112,298
2
3           2,114,235,145,126,123,141
..          .. 

I am trying to replace these blank rows with '0' in my query but so far failed to do so:

Select
      Case when my_tbl.my_array = ' '
      then '0'
      else my_array
      end as array
from my_table

The query runs but no result. Can somebody help to me to replace blanks rows using case statement or otherwise?

2
  • use my_tbl.my_array = '{}' in case to check for empty arrays. Commented Jun 15, 2017 at 12:34
  • I used, CASE when my_table.my_array = '{}' then '{0}'... but didn't work. Commented Jun 15, 2017 at 12:38

1 Answer 1

2

Use coalesce():

select id, coalesce(my_array, '0') as my_array
from my_table;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.