Searching for a particular value in a jsonb datatype prostgresql

假如想象 提交于 2019-12-24 06:16:05

问题


We are storing dynamic json data to a postgresql jsonb datatype field. Most of the json keys are dynamic and nested.

Now I need to search one particular value inside this json data field. This value may be present with any key name.

row1 = { "header": { "piecesids" : [100,200,300] }, "footer" : {"pieceids" : [500,300]} }

row2 = { "header_right": { "piecesids" : [500,300,400] }, "footer_left" : {"pieceids" : [300,200]} }

row3 = { "body_right": { "piecesids" : [500,300,600] }, "body_left" : {"pieceids" : [300]} }

I need all the rows where pieceid 200 is present that means I want row1 & row2 to be returned.

I have gone through several blogs, but all mentions how we can search by key but not by value.

来源:https://stackoverflow.com/questions/43252423/searching-for-a-particular-value-in-a-jsonb-datatype-prostgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!