简体   繁体   English

从SQL中的数组中删除空值

[英]Remove nulls from an array in SQL

Want to remove nulls from an array in hive/sql 想要从hive / sql中的数组中删除空值

for example : array is ['1',null] after converting to string values it should be '1' only. 例如:在转换为字符串值后,数组为['1',null],它应该只为'1'。

to split the array I am using below: 拆分我在下面使用的数组:

concat_ws( ",", array_val)

this gives : 1,null

required output : 1

Thanks for the help! 谢谢您的帮助!

Use regexp_replace to remove null from concatenated string: 使用regexp_replace从连接字符串中删除null:

hive> select regexp_replace('null,1,2,null,2,3,null','(,+null)|(^null,)','');
OK
1,2,2,3
Time taken: 6.006 seconds, Fetched: 1 row(s)

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

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