未保留空字符串

k4aesqcs  于 2021-06-27  发布在  Hive
关注(0)|答案(2)|浏览(228)

在表中插入包含空字符串的数据,然后执行

select * from tableA;

我看到空字符串被null值替换。
如何保留空字符串值而不是空值?

rqqzpn5f

rqqzpn5f1#

刚发现。。。原因是,当在需要字符串的字段中使用空值插入时,将保留空值,但当字段需要字符串以外的内容时,例如,如果字段希望接收整数,则将空值作为空值插入。

r7s23pms

r7s23pms2#

您应该得到不为null的空字符串。

hive> create temporary table t1 as select '' as c1, 
' ' as c2; --- ' ' space
Time taken: 0.145 seconds, Fetched: 1 row(s)
hive> select concat('|',c1, '|', c2, '|') from t1;
OK
|| |
Time taken: 0.319 seconds, Fetched: 1 row(s)

hive> insert into t1 values ('  ', '   '); -- multiple spaces
Time taken: 13.6 seconds
hive> select concat('|',c1, '|', c2, '|') from t1;
OK
|| |
|  |   |
Time taken: 0.136 seconds, Fetched: 2 row(s)

相关问题