기본적으로 jsonb 유형의 열이있는 postgresql 테이블이 있습니다. JSON 데이터가 내 PostgreSQL의 명령 줄에서 "화성"과 "테란"국적 ..이 모든 사람을 인출 할이postgresql에서 jsonb 열을 검색하는 방법
{
"personal": {
{
"gender":"male",
"contact":{
"home":{
"email":"[email protected]",
"phone_number":"5551234"
},
"work":{
"email":"[email protected]",
"phone_number":"5551111"
}
},
"religion":"other",
"languages":[
"English",
"Xen"
],
"last_name":"Eeo",
"birth_date":"1945-07-28",
"first_name":"Cee",
"nationality":"Martian",
"marital_status":"married"
}
}
}
처럼 보이는이이 작품
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
새로운 질문 (관련) http://stackoverflow.com/questions/38324360/how-to-use-postgresql-any-with-jsonb-data – abbood