我有一个带product_data列(JSONB类型)的产品表,数据采用以下格式。
[{
"Price": 34599,
"Units": 1,
"productId": 3,
"componentId": 0,
"isDuplicate": false,
"productCode": "PRD-3",
"productName": "OnePlus 6T",
"UnitDiscount": 0,
"discountType": "1",
"componentCode": "",
"componentList": [{
"componentId": 5,
"componentCode": "ACC-1",
"componentName": "Charger",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}, {
"componentId": 6,
"componentCode": "ACC-2",
"componentName": "Earphone",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}],
"productUnitPrice": 34599,
"UnitPriceDiscount": 34599,
"componentCategory": "",
"componentUnitPrice": ""
}, {
"Price": 1200,
"Units": 1,
"productId": 3,
"componentId": 5,
"isDuplicate": false,
"productCode": "PRD-3",
"productName": "OnePlus 6T",
"UnitDiscount": 0,
"discountType": "1",
"componentCode": "ACC-1",
"componentList": [{
"componentId": 5,
"componentCode": "ACC-1",
"componentName": "Charger",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}, {
"componentId": 6,
"componentCode": "ACC-2",
"componentName": "Earphone",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}],
"componentName": "Charger",
"productUnitPrice": "",
"UnitPriceDiscount": 1200,
"componentCategory": "General",
"componentUnitPrice": "1200"
}, {
"Price": 800,
"Units": 1,
"productId": 3,
"componentId": 6,
"isDuplicate": false,
"productCode": "PRD-3",
"productName": "OnePlus 6T",
"UnitDiscount": 0,
"discountType": "1",
"componentCode": "ACC-2",
"componentList": [{
"componentId": 5,
"componentCode": "ACC-1",
"componentName": "Charger",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}, {
"componentId": 6,
"componentCode": "ACC-2",
"componentName": "Earphone",
"componentActive": true,
"componentTaxCode": null,
"componentCategory": "General",
"componentUnitPrice": 0,
"componentCategoryId": 1,
"componentReorderValue": 20
}],
"componentName": "Earphone",
"productUnitPrice": "",
"UnitPriceDiscount": 800,
"componentCategory": "General",
"componentUnitPrice": "800"
}]
当从下面的查询中获取数据时,当在查询中复制此数据时,当JSONB数据为数组形式时,它显示无法获取标量元素,请提供帮助。
SELECT product_data from (
SELECT jsonb_array_elements(PRODUCT_DATA) as product_data FROM PRODUCTS
) X
同时将此jsonb数据而不是列复制到查询中,然后工作正常。