查询搜索JSONB PSQL中的数组元素
我有一个JSON节点,我必须在上面写一个PSQL查询,我的表格架名称(字符串),TagValues(JSONB)。示例tagvalue数据在下面给出了
name_tagstable,
uid | name(String)| tagValues(jsonb)
-----+-------------------+-----------------------------
1 | myName | { "tags": ["xyz","pqr","xyp"]}
我需要一个查询,该查询返回表上的搜索“ pq”的所有行
select * from Name_TagsTable where tagValues->tags contains %pq%
I have a JSON node on which I have to write a PSQL query, My table schema name(String),tagValues(jsonb). Example tagValue data is given below
Name_TagsTable
uid | name(String)| tagValues(jsonb)
-----+-------------------+-----------------------------
1 | myName | { "tags": ["xyz","pqr","xyp"]}
I need a query that returns all rows for a search "pq" made on the tagValues of the table
select * from Name_TagsTable where tagValues->tags contains %pq%
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
喜欢
运算符以及铸造JSONB
值You can use
LIKE
operator along with castingJSONB
value to a string type such as您需要解开元素,然后可以在适用类似条件的情况下使用它。
You need to unnest the elements, then you can use it in a WHERE condition that applies a LIKE condition.