Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 从postgres中的jsonb列中选择json值_Postgresql_Jsonb - Fatal编程技术网

Postgresql 从postgres中的jsonb列中选择json值

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

以下是我对我的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\": [{\"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}]}');