I have a table with below columns and data types.
id string
name string
title string
listItems string
purchase_list table:
id | name | title | listItems |
---|---|---|---|
123 | Peter | Purchase List | [{"manufacture_date":"2023-01-01","purchase_price":"20.0"}, {"manufacture_date":"2023-01-02","purchase_price":"30.0"}] |
Query used:
with raw_data as
(
select
id
, name
, title
, json_parse(listItems) as listItems
from purchase_list
)
select
id
, name
, title
, json_extract_scalar(listItems,'$.manufacture_date') as manufacture_date
, json_extract_scalar(listItems,'$.purchase_price') as purchase_price
from raw_data
Expected output:
id | name | title | manufacture_date | purchase_price |
---|---|---|---|---|
123 | Peter | Purchase List | 2023-01-01 | 20.0 |
123 | Peter | Purchase List | 2023-01-02 | 30.0 |
When I extract data using json_extract_scalar, I am getting blank values
id | name | title | listItems |
---|---|---|---|
123 | Peter | Purchase List |
Please advise how I can achieve the expected output.