简体   繁体   English

如何使用 BIGQUERY 提取数组中每个项目的最后 8 个元素

[英]How to extract the last 8 elements of each item on an array using BIGQUERY

I have a column that is an array, like ["551199999999","55129999999999","5532999999999]. Using BigQuery, I used JSON_EXTRACT_STRING_ARRAY(column) and I get the items split on a list. Now, I want to get the last 8 string of each item of the array, I've trid RIGHT(JSON_EXTRACT_STRING_ARRAY(column)) but I got an erro. Anyone know how to do that?我有一列是一个数组,例如 ["551199999999","55129999999999","5532999999999]。使用 BigQuery,我使用 JSON_EXTRACT_STRING_ARRAY(column) 并将项目拆分到一个列表中。现在,我想得到最后一个数组中每个项目的 8 个字符串,我已经尝试过 RIGHT(JSON_EXTRACT_STRING_ARRAY(column)) 但我遇到了错误。有人知道该怎么做吗?

You need to UNNEST an array first and apply RIGHT() function to each item of the array like below.您需要先UNNEST一个数组,然后将RIGHT() function 应用于数组的每个项目,如下所示。

 WITH sample AS (
   SELECT '["551199999999","55129999999999","5532999999999"]' json
 )
 SELECT RIGHT(item, 8) 
   FROM sample, UNNEST(JSON_VALUE_ARRAY(json)) item;

-- Query results
+-----+----------+
| Row |   f0_    |
+-----+----------+
|   1 | 99999999 |
|   2 | 99999999 |
|   3 | 99999999 |
+-----+----------+

And prefer to use new JSON functions instead of using legacy ones.并且更喜欢使用新的 JSON 函数而不是使用旧函数。

在此处输入图像描述

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

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