在postgresql中我有一列是JSON类型,我有以下数据:
requests.get()
对于这个示例数据,我需要从基中提取数据到键名“ row1”和“ row2”。
我已经尝试了以下句子,但没有成功:
["row1", {
"date": "05/30/2019",
"name": "JOSH",
"discount": "160.00"
}, {
"date": "04/30/2019",
"name": "JOSH",
"discount": "170.00"
}, {
"date": "03/30/2019",
"name": "JOSH",
"discount": "79.00"
}, "row2", {
"date": "05/30/2019",
"name": "MARIO",
"discount": "110.00"
}, {
"date": "04/30/2019",
"name": "MARIO",
"discount": "101.00"
}, {
"date": "03/30/2019",
"name": "MARIO",
"discount": "98.00"
}]
现在总是显示空结果,例如,我需要提取'row1'
select data->>'row1' from discounts;
SELECT *
FROM discounts
WHERE json_arr_record_keys(data->'row1');
SELECT *
FROM discounts
WHERE EXISTS (
SELECT 1
FROM json_array_elements(data->'row1') elem
);