Postgresql 从postgres中的jsonb列中选择json值
以下是我对我的postgres表的插入请求:Postgresql 从postgres中的jsonb列中选择json值,postgresql,jsonb,Postgresql,Jsonb,以下是我对我的postgres表的插入请求: insert into pay_process (created, execution_time, updated, bundle_id, processing_status, xxi_balance) values (current_timestamp, current_timestamp, current_timestamp, 1, 'SUCCESS', '"{\"balances\": [{\&qu
insert into pay_process (created, execution_time, updated, bundle_id, processing_status, xxi_balance)
values (current_timestamp, current_timestamp, current_timestamp, 1, 'SUCCESS',
'"{\"balances\": [{\"bs_day\": \"2021-02-12\", \"balance\": 1167.18}, {\"bs_day\": \"2021-02-13\", \"balance\": 4796.45}]}"');
xxi_天平为jsonb型。我需要选择我的余额数组,我使用以下请求:
select xxi_balance::json->'balances' as balances from pay_process;
但它什么也不返回。我的错误是什么?您存储的是一个大的JSON标量,而不是一个嵌套的JSON对象。您需要删除整个值周围的双引号和值内部的转义双引号:
insert into pay_process
(created, execution_time, updated, bundle_id, processing_status, xxi_balance)
values
(current_timestamp, current_timestamp, current_timestamp, 1, 'SUCCESS',
'{"balances": [{"bs_day": "2021-02-12", "balance": 1167.18}, {"bs_day": "2021-02-13", "balance": 4796.45}]}');
您存储的是一个大的JSON标量,而不是一个嵌套的JSON对象。您需要删除整个值周围的双引号和值内部的转义双引号:
insert into pay_process
(created, execution_time, updated, bundle_id, processing_status, xxi_balance)
values
(current_timestamp, current_timestamp, current_timestamp, 1, 'SUCCESS',
'{"balances": [{"bs_day": "2021-02-12", "balance": 1167.18}, {"bs_day": "2021-02-13", "balance": 4796.45}]}');