作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 json 类型的列,但我想知道如何选择过滤它,即
select * from fooTable where myjson like "orld";
我将如何查询像上面这样的子字符串匹配。假设在“栏”键下搜索“orld”?
{ "foo": "hello", "bar": "world"}
我看了一下这个文档,但它很困惑。
https://www.postgresql.org/docs/current/static/datatype-json.html
最佳答案
使用 ->>
operator以文本形式获取 json 属性,示例
with my_table(id, my_json) as (
values
(1, '{ "foo": "hello", "bar": "world"}'::json),
(2, '{ "foo": "hello", "bar": "moon"}'::json)
)
select t.*
from my_table t
where my_json->>'bar' like '%orld'
id | my_json
----+-----------------------------------
1 | { "foo": "hello", "bar": "world"}
(1 row)
请注意,您需要在模式中使用占位符 %
。
关于postgresql - Postgres : How to string pattern match query a json column?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49740223/
我是一名优秀的程序员,十分优秀!