私は基本的に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')
をしかし、私はこの1つのような書式設定のエラーを取得:
あなたはこれを実現するために、「テキストとして値を取得し、」オペレータ->>
使用する必要が0
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