[英]how to search jsonb column in postgresql ( not nested column )
我的架構:
create table blog (
id SERIAL PRIMARY KEY,
title varchar,
tags jsonb
);
我的查詢:
const tags = "horr";
const query = `SELECT * FROM blog where tags like '%${tags}%'`;
我想要什么:
現在我只想得到 "tags" 列包括"horror" 。 但我只想用“恐怖”
我知道這個查詢不起作用。 但想在下面這樣做
"rows": [
{
"id": 1,
"title": "horror stroy",
"tags": [
"sad",
"horror"
]
}
]
您需要取消嵌套所有標簽才能使用 LIKE 條件
select b.*
from blog b
where exists (select *
from jsonb_array_elements_text(b.tags) as x(tag)
where tag ilike 'horr%');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.