我尝试在JSON对象中的指定路径获取item_sku元素。
我有一个列,我只想使用postgresql提取item_sku添加到一个列中。我该怎么做才能解决这个问题?
下面是我正在尝试的代码:
select o.reference,
o.id as "ord_id",
o.created_at,
o.aasm_state,
o.payment_details -> 'payment_method' as "payment_method",
max(gr.updated_at) as "last_updated_at",
o.shipping_address -> 'country' as "country",
(gr.request_body -> 0 #>> '{lines}') as ESD
这里的结果我得到:
[{"item_sku": "60997070103", "image_url": "https://hahaha", "identifier": "7713128"}, {"item_sku": "60997070103", "image_url": "https://hahha", "identifier": "7713131"}, {"item_sku": "62007100402", "image_url": "https://hahha", "identifier": "7713129"}]
以下是我试图获得的信息的数据:
[{"lines": [{"item_sku": "60997070103", "image_url": "https://hahaha", "identifier": "7713128"}, {"item_sku": "60997070103", "image_url": "https://hahha", "identifier": "7713131"}, {"item_sku": "62007100402", "image_url": "https://hahha", "identifier": "7713129"}]
1条答案
按热度按时间ttvkxqim1#
SELECT gr.request_body #>> '{0,lines,0,item_sku}'
将产生"60997070103"SELECT gr.request_body #>> '{0,lines,1,item_sku}'
将产生"60997070103"SELECT gr.request_body #>> '{0,lines,2,item_sku}'
将产生"62007100402"将导致
| 项目_SKU|
| - ------|
| 小行星60|
| 小行星60|
| 小行星62007|
参见dbfiddle