简体   繁体   English

大查询 JSON 提取 Function

[英]Big Query JSON Extract Function

I'm extracting 2 fields from a JSON using JSON_EXTRACT using BQ as the following:我使用 BQ 使用 JSON_EXTRACT 从 JSON 中提取 2 个字段,如下所示:

select JSON_EXTRACT_SCALAR('Event_Value','$.user_id') as cid, JSON_EXTRACT_SCALAR('Event_Value','$.tsts') as ts

if the JSON format is missing one of the field I'm receiving NULLs all over the place.如果 JSON 格式缺少其中一个字段,我将在所有地方收到 NULL。

Is there a way to overcome it?有办法克服吗?

I feel the fix is quite simple:我觉得修复很简单:

select JSON_EXTRACT_SCALAR(Event_Value,'$.user_id') as cid, JSON_EXTRACT_SCALAR(Event_Value,'$.tsts') as ts    

So, there are extra ' around Event_Value - thus Event_Value was treated not as a column name but rather as string因此,在Event_Value周围有额外' - 因此Event_Value不被视为列名,而是被视为字符串

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

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