I have a crate db table with records like the one below:
{
"businessareaname": "test",
"profile": {
"phone": "",
"fullname": "",
"email": "abe-10@spatially.com"
}
}
I've tried querying with:
select *
from myTable
where profile['email'] = 'abe-10@spatially.com';
but nothing get's returned. How can I pull records based on an email value that is in an object?
This isn't a flat table so this is my best attempt at showing the table structure. The first row is the header and the next two rows are data.
business name | profile:
- phone
- fullname
- email
-------------------------------------
"test" | ""
""
"abe-10@spatially.com"
-------------------------------------
"other one" | "(415)884-9938"
"Abe Miessler"
"abe@test.com"
The example you wrote should work and is correct.
Reasons it might not work is that the table schema is not correct, specifically:
INDEX OFF
IGNORED
Here a full working example:
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';
If piped into crash
this would output:
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)