Querying Postgres 9.6 JSONB array of objects

后端 未结 2 2467
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 17:56

I have the following table:

CREATE TABLE trip
(
    id SERIAL PRIMARY KEY ,
    gps_data_json jsonb NOT NULL
);

The JSON in gps_data_json conta

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-20 19:00

    Unnesting the array works fine, if you only want the objects containing the values queried. The following checks for containment and returns the full JSONB:

    SELECT * FROM trip
    WHERE gps_data_json @> '[{"mode": "WALK"}]';
    

    See also Postgresql query array of objects in JSONB field

提交回复
热议问题