![](/img/trans.png)
[英]How to extract elements from Presto ARRAY(MAP(VARCHAR, VARCHAR))
[英]Presto: Extract values from a string column, which is similar to map, but not a map
我有一張桌子:
Name pets
--------------
Andy {"cat":2, "dog":1, "bird":4 ,xxx}
John {"dog":3, "cat":1, "bird":{}, uyx}
Mary {"dog":2, "duck":{}, "cat":1, zzz}
pets 列是 map,但創建的表是一個字符串,其中有一些額外的字符。 所以我不能使用cast(json_parse(pets) as map(varchar, varchar)) AS m
。
在這種情況下,如果我想找出"cat"
的值,我該怎么做? 謝謝!
您可以使用regexp_extract()
:
select t.*,
regexp_extract(pets, '"cats":([^,]*)', 1)
from t;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.