简体   繁体   English

如何在PostgreSQL中使用CASE语句替换文本数组中的空白行?

[英]How do I replace blanks rows in text array using CASE statment in PostgreSQL?

I have 12 unique IDs in my PostgreSQL 9.5 table for which some array (text) are blanks: 我的PostgreSQL 9.5表中有12个唯一ID,其中某些数组(文本)为空白:

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: 我正在尝试在查询中将这些空白行替换为'0' ,但到目前为止未能做到:

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? 有人可以帮助我使用case语句替换空白行吗?

Use coalesce() : 使用coalesce()

select id, coalesce(my_array, '0') as my_array
from my_table;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM