【问题标题】:Extracting data from JSON field in Amazon Redshift从 Amazon Redshift 中的 JSON 字段中提取数据
【发布时间】:2019-03-28 14:27:12
【问题描述】:

我正在尝试从 Redshift 中的 JSON 字段中提取一些数据。

下面是我正在处理的数据的示例视图。

{"fileFormat":"excel","data":{"name":John,"age":24,"dateofbirth":1993,"Class":"Computer Science"}}

我能够提取第一级的数据,即对应于的数据 fileFormatdata 如下:

select CONFIGURATION::JSON -> 'fileFormat' from table_name;

我正在尝试提取data 下的信息,例如nameagedateofbirth

【问题讨论】:

    标签: sql json amazon-redshift


    【解决方案1】:

    你可以使用 Redshift 的原生函数 json_extract_path_text
    - https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html

    SELECT
      json_extract_path_text(
        configuration,
          'data',
          'name'
      )
        AS name,
      json_extract_path_text(
        configuration,
          'data',
          'age'
      )
        AS age,
      etc
    FROM
      yourTable
    

    【讨论】:

    • @scottmartin - 不客气,请随时投票并接受对您有帮助的答案;)
    • 会的。它要求我再等 10 分钟才能接受答案..
    猜你喜欢
    • 2022-08-24
    • 1970-01-01
    • 2020-12-04
    • 2022-01-16
    • 1970-01-01
    • 2019-07-22
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多