在redshift中提取具有相同键的键值对

Extract key value pairs with the same key in redshift

我有一个要求,即在列的每个单元格上都有一个 json 数组。我试图找到一种方法来提取相同键值对的每个实例。例如,我想从以下数组中提取每次出现的 'product_id':

[{“id”:11993176146155,“fulfillable_quantity”:0,“product_id”:7538905317611,“属性”:[],“数量”:1,“requires_shipping": true, "taxable": false, "total_discount": "0.00", "total_discount_set": {"shop_money": {"amount": "0.00" , "currency_code": "PKR"}, "presentment_money": {"amount": "0.00", "currency_code": "PKR"}}}, {"id" : 11993176178923, "price_set": {"shop_money": {"金额": "450.00", "currency_code": "PKR"}, "presentment_money": {"金额": "450.00", "currency_code": "PKR"}}, "product_exists": true, "product_id": 7018040164543}]

我想创建一个名为 'Product_ID' 的新列,并将提取的值存储在该列中。我的最终结果应该是这样的:

在 redshift 中有没有办法为每一行遍历整个数组并提取所需的值(在本例中是产品 ID)?我已经查看了 redshift 上的一些功能,但不幸的是那些没有帮助。如果有人能提供解决方案就太好了。

您需要取消嵌套数组,然后 select 您想要的键。

这里有一个关于在 Redshift 中取消数组嵌套的很棒的教程:https://blog.getdbt.com/how-to-unnest-arrays-in-redshift/