Я использую postgresql 10.6. В моей таблице есть столбец jsonb travel
, заполненный приведенными ниже образцами данных. Ниже приведено sqlfiddle:
http://sqlfiddle.com/#!17/e52ff/1
Мой стол:
id | travel
-: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | {"name": "Lucy", "trips": [{"city": "Tokyo", "continent": "Asia"}, {"city": "Bangkok", "continent": "Asia"}, {"city": "Paris", "continent": "Europe"}, {"city": "London", "continent": "Europe"}]}
2 | {"name": "Tom", "trips": [{"city": "Tokyo", "continent": "Asia"}, {"city": "Kyoto", "continent": "Asia"}, {"city": "Frankfurt", "continent": "Europe"}, {"city": "London", "continent": "Europe"}]}
3 | {"name": "Lenny", "trips": [{"city": "Tokyo", "continent": "Asia"}, {"city": "Bangkok", "continent": "Asia"}, {"city": "New York", "continent": "America"}, {"city": "Seattle", "continent": "America"}]}
DDL и введите код:
create table people (
id serial primary key,
travel jsonb
);
insert into people (travel) values (
'{
"name": "Lucy",
"trips": [
{
"continent": "Asia",
"city": "Tokyo"
},
{
"continent": "Asia",
"city": "Bangkok"
},
{
"continent": "Europe",
"city": "Paris"
},
{
"continent": "Europe",
"city": "London"
}
]
}
'::jsonb);
insert into people (travel) values (
'{
"name": "Tom",
"trips": [
{
"continent": "Asia",
"city": "Tokyo"
},
{
"continent": "Asia",
"city": "Kyoto"
},
{
"continent": "Europe",
"city": "Frankfurt"
},
{
"continent": "Europe",
"city": "London"
}
]
}
'::jsonb);
insert into people (travel) values (
'{
"name": "Lenny",
"trips": [
{
"continent": "Asia",
"city": "Tokyo"
},
{
"continent": "Asia",
"city": "Bangkok"
},
{
"continent": "America",
"city": "New York"
},
{
"continent": "America",
"city": "Seattle"
}
]
}
'::jsonb);
Какмогу ли я запросить информацию о поездках в города с буквой "o" на континенте Азия ?
Спасибо и всего наилучшего