且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查询Postgres 9.6 JSONB对象数组

更新时间:2023-02-05 15:04:03

出现问题是因为->>运算符无法遍历数组:

The problem arises because ->> operator cannot walk through array:

  • 首先使用json_array_elements函数取消嵌套json数组;
  • 然后使用运算符进行过滤.
  • First unnest your json array using json_array_elements function;
  • Then use the operator for filtering.

以下查询可解决问题:

WITH 
A AS (
SELECT
    Id
   ,jsonb_array_elements(gps_data_json) AS point
FROM trip
)
SELECT *
FROM A
WHERE (point->>'mode') = 'WALK';