【发布时间】:2016-07-11 13:37:50
【问题描述】:
我基本上有一个包含 jsonb 类型列的 postgresql 表。 json数据是这样的
{
"personal": {
{
"gender":"male",
"contact":{
"home":{
"email":"ceo@home.me",
"phone_number":"5551234"
},
"work":{
"email":"ceo@work.id",
"phone_number":"5551111"
}
},
"religion":"other",
"languages":[
"English",
"Xen"
],
"last_name":"Eeo",
"birth_date":"1945-07-28",
"first_name":"Cee",
"nationality":"Martian",
"marital_status":"married"
}
}
}
我想获取所有具有“火星人”和“人族”国籍的人......在我的 postgresql 命令行中这是可行的
select employees->'personal'->'contact'->'work'->'email'
from employees
where employees->'personal' @> '{"nationality":"Martian"}'
or employees->'personal' @> '{"nationality":"Terran"}'
这可行.. 但它很丑.. 我想运行这样的东西:
select employees->'personal'->'contact'->'work'->'email'
from employees
where employees->'personal'->'nationality' in ('Martian','Terran')
但我收到这样的格式错误:
DETAIL: Token "Martian" is invalid.
CONTEXT: JSON data, line 1: Martian
【问题讨论】:
标签: postgresql jsonb