Postgresql 在psotgreSql中的json类型coloumn中搜索
我有一个类似这样的jsonPostgresql 在psotgreSql中的json类型coloumn中搜索,postgresql,Postgresql,我有一个类似这样的json { "dbInfo":{ "id":"F", "lifeTime":"ACTIVE" }, "name":{ "firstName":"abc", "lastName":"xyz" }, "contactDetails":{ "email":{ "localPart":
{
"dbInfo":{
"id":"F",
"lifeTime":"ACTIVE"
},
"name":{
"firstName":"abc",
"lastName":"xyz"
},
"contactDetails":{
"email":{
"localPart":"abc",
"domain":"gmail.com"
},
"mobile":[
{
"code":"ISD_91",
"number":"9658321407"
}
]
},
"type":{
"personType":"WORKER"
}
}
我想在数据库中执行搜索,其中
number=9658321407
它将在postgresql数据库中向我返回整个json。有人能帮我写我的查询吗?我想得到所有有这个数字的json,如果我有多个数字,我如何搜索?使用以下格式获得结果 --如果传递的值是整数
select * from "Your_table" where (select json_array_elements(json_extract_path(json_extract_path("Your_CloumnName",'contactDetails'),'mobile'))->> 'number')::bigint = 9658321407
--如果传递的值是string
select * from "Your_table" where (select json_array_elements(json_extract_path(json_extract_path("Your_CloumnName",'contactDetails'),'mobile'))->> 'number')= '9658321407'
但是string就是我为什么使用bigint的原因吗