我有一个包含以下记录的crate db表:
{
"businessareaname": "test",
"profile": {
"phone": "",
"fullname": "",
"email": "abe-10@spatially.com"
}
}
我尝试过查询:
select *
from myTable
where profile['email'] = 'abe-10@spatially.com';
但没有得到任何回报。如何根据对象中的电子邮件值提取记录?
这不是一个平面表,所以这是我展示表结构的最佳尝试。第一行是标题,接下来的两行是数据。
business name | profile:
- phone
- fullname
- email
-------------------------------------
"test" | ""
""
"abe-10@spatially.com"
-------------------------------------
"other one" | "(415)884-9938"
"Abe Miessler"
"abe@test.com"
答案 0 :(得分:3)
你写的例子应该有效并且是正确的。
可能无效的原因是表架构不正确,具体为:
INDEX OFF
IGNORED
这是一个完整的工作示例:
create table t1 (profile object as (email string));
insert into t1 (profile) values ({email='abe-10@spatially.com'});
refresh table t1;
select * from t1 where profile['email'] = 'abe-10@spatially.com';
如果通过管道输入crash
,则会输出:
CONNECT OK
CREATE OK, 1 row affected (0.286 sec)
INSERT OK, 1 row affected (0.082 sec)
REFRESH OK, 1 row affected (0.065 sec)
+-----------------------------------+
| profile |
+-----------------------------------+
| {"email": "abe-10@spatially.com"} |
+-----------------------------------+
SELECT 1 row in set (0.087 sec)