[英]How do I extract all JSON values from all keys in SQL Bigquery?
I have a json string in bigquery that looks like that:我在 bigquery 中有一个 json 字符串,看起来像这样:
{"1":"eggs","2":"nuts","3":"fish"}
How could I extract all values without listing the keys?我如何在不列出键的情况下提取所有值? What I need is:
我需要的是:
['eggs', 'nuts', 'fish']
I've tried [json_extract(json_string, '$[1]'), json_extract(json_string, '$[2]')]
and it does the job but it won't work if the number of keys increases我试过
[json_extract(json_string, '$[1]'), json_extract(json_string, '$[2]')]
并且它完成了工作但是如果键的数量增加它就不会工作
I managed to do this using this query:我设法使用这个查询来做到这一点:
CREATE TEMP FUNCTION jsonObjectValues(input STRING)
RETURNS Array<String>
LANGUAGE js AS """
RETURN Object.values(JSON.parse(input));
""";
SELECT
jsonObjectValues(value) AS values
FROM my_dataset
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.