PostgreSQL 是否支持在 jsonb 列类型中使用 MySQL 'RLIKE'/Regexp 语句?
例如,需要一个从下表中提取所有包含值“大”的 ID 的查询:
| data |
| "id" :"bigData" , "content" : "aaa...." |
| "id" : "biggerData, "content" : "bbb..."|
| "id": "smallData", "content: "ddd......"|
Select * from myTable where data Rlike ...
是否适用?
最佳答案
如果该列包含有效的 json 对象,您可以使用 the ->> operator和简单的 LIKE
或 ILIKE
运算符:
with my_table(data) as (
values
('{"id": "bigData" , "content": "aaa...."}'::jsonb),
('{"id": "biggerData", "content": "bbb..."}'),
('{"id": "smallData", "content": "ddd......"}')
)
select *
from my_table
where data->>'id' like '%big%';
data
-------------------------------------------
{"id": "bigData", "content": "aaa...."}
{"id": "biggerData", "content": "bbb..."}
(2 rows)
在更复杂的情况下,您还可以使用 the regex pattern matching operator ~ ,例如:
select *
from my_table
where data->>'id' ~ 'big.*Data';
关于database - Postgres 是否支持 jsonb 列类型中的 Ilike 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47978077/