Clickhouse Nullable列的轉(zhuǎn)換處理 Nested type Array(String) cannot be inside Nullable type (version 19.5....

直接看解決方案請(qǐng)翻到最后一行

1.Nullable列

優(yōu)點(diǎn):允許Null值插入,在導(dǎo)數(shù)時(shí)對(duì)null值不需要額外處理
缺點(diǎn),Nullable 列相比普通列需要額外的存儲(chǔ)空間且對(duì)性能有一些影響,且一些函數(shù)splitByString對(duì)Nullable列是不支持的

2.轉(zhuǎn)換處理

我們在建表時(shí)幾乎每個(gè)列都加上了Nullable,這就導(dǎo)致了處理這些列遇見一些問題
例如names Nullable(String)字段,我想要按逗號(hào)切分這個(gè)names

select splitByString(',',names) from table

會(huì)報(bào)如下錯(cuò)誤
DB::Exception: Nested type Array(String) cannot be inside Nullable type (version 19.5.3.1)
那么如何解決這個(gè)問題呢?當(dāng)然是把Nullable(String)轉(zhuǎn)換成String了
剛開始試一下了幾種方法

  • toString(names)
  • substring(name,1,length(name)) + 別名
  • concat(names,'') + 別名
  • 組合查詢
  • 子查詢
    發(fā)現(xiàn)并沒有什么 軟 用

后來換成cast(names as String)成功解決問題

select splitByString(',',cast(names as String)) from table
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容