在PostgreSQL的jsonb字段中使用LIKE运算符处理对象数组 [英] Using LIKE operator for array of objects inside jsonb field in PostgreSQL

查看:698
本文介绍了在PostgreSQL的jsonb字段中使用LIKE运算符处理对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对PostgreSQL 9.4中jsonb字段的对象数组内的单个键/值使用LIKE运算符?例如,我有:

Is it possible to use LIKE operator for single key/value inside array of objects for jsonb field in PostgreSQL 9.4? For example I have:

 id |                  body                                                              
------------------------------------------------------------
  1 | {"products": [{"name": "qwe", "description": "asd"}, {"name": "zxc", "description": "vbn"}]}

我知道,我可以得到这样的product:

I know, I can get a product with something like this:

select * from table where 'body'->'products' @> '[{"name": "qwe"}]'::jsonb

问题是:如果我不知道它的全名,我可以得到这个产品吗?

The question is: can I get this product if I don't know full name of it?

推荐答案

尝试使用

输出如下:

 key  | value 
------+-------
 name | "qwe"
(1 row)

这篇关于在PostgreSQL的jsonb字段中使用LIKE运算符处理对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆