简体   繁体   English

Json 中的 AWS Athena 提取数组

[英]AWS Athena Extract Array in Json

I have a json column and inside this json column is an array structure.我有一个 json 列,这个 json 列里面是一个数组结构。 I couldn't figure out how to get the array there.我无法弄清楚如何将阵列放在那里。

I trİed to this我试过这个

 cast(json_extract(ise, '$.userservice') as varchar)  as ise_user_service

Example Json示例 Json

ise
        {
       "userpa":"****",
       "userlo":"*****",
       "sessi":"******",
       "cl":{
          "name":"****",
          "id":"*****"
       },
       "usermains":"******",
       "userservice":[
          "1****",
          "23***4**",
          "124****",
          "034****"
       ],
       "usergeoloc":"********",
       "userparty":"*******"
    }

You can either use json_format to turn it into string or cast to ARRAY(VARCHAR) depending on the usecase:您可以根据用例使用json_format将其转换为字符串或转换为ARRAY(VARCHAR)

WITH dataset AS (
    SELECT * FROM (VALUES   
       ( JSON ' {
       "userpa":"****",
       "userlo":"*****",
       "sessi":"******",
       "cl":{
          "name":"****",
          "id":"*****"
       },
       "usermains":"******",
       "userservice":[
          "1****",
          "23***4**",
          "124****",
          "034****"
       ],
       "usergeoloc":"********",
       "userparty":"*******"
    }')
 ) AS t (ise))

 
SELECT json_format(json_extract(ise, '$.userservice')) as ise_string, 
    cast(json_extract(ise, '$.userservice') as ARRAY(VARCHAR)) as ise_array
FROM dataset

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

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