【问题标题】:JSON column in Redshift: alternative to jsonb_each?Redshift 中的 JSON 列:替代 jsonb_each?
【发布时间】:2021-01-18 13:45:37
【问题描述】:

我正在将我的数据库表从 postgres 移动到 Redshift,以下查询不再有效:

select dr.id, dr.opportunity_id, dr.roi -> 'data' ->> 'campaignName' as campaign_Name,
users.value ->> 'name' as influencer_name, users.value ->> 'id' as influencer_dyzio_id, 
users.value -> 'instagramCount' as instagram_Count, users.value -> 'instagramEngagementFactor' as instagram_Engagement_Factor,
users.value -> 'emv' ->> 'estimatedImpressions' as emv_estimated_Impressions,
users.value -> 'emv' ->> 'impressionsCPM' as emv_impressions_CPM,
users.value -> 'emv' ->> 'engagementsCPM' as emv_engagements_CPM, 
users.value ->> 'platformID' as platform_ID
FROM platform_db.dyzio_rois dr, jsonb_each(roi -> 'data' -> 'reportData') as users

如何使用 Redshift 使其工作?

【问题讨论】:

    标签: json amazon-redshift


    【解决方案1】:

    由于 Redshift 没有本机 json 数据类型,因此 Redshift SQL 中没有与 jsonb_each() 等效的函数,该函数适用于所有情况 AFAIK。在某些情况下,特定于用例的 Redshift SQL 可能是可行的,而 UDF 在其他情况下可能是可行的。需要有关源数据和预期结果的更多信息,以帮助为您的用例生成解决方案。

    Redshift 支持以文本形式存储的 json,并具有从这些字符串中提取信息的功能。 json_extract_path_text() 就是这样一种函数,它将根据字符串中使用的 json 键提取文本值。这被构造为表中每行一个字符串(json)。由于您在 Redshift 中工作,我假设您已经以这种方式将 json 存储为字符串。 Postgres 中的 jsonb_each() 将 json blob 中的元素扩展为数据行。可以根据 json-storing-text 列中的元素扩展行,但您可能需要考虑您的数据模型以及为什么要在 json 文本列中存储多个“行”数据 (roi -> 'data' -> '报告数据')。这样做会很慢而且很难查询。

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多