如何根据object值查询?

How to query based on object value?

我有一个 crate db table,其中包含如下记录:

  {
    "businessareaname": "test",
    "profile": {
      "phone": "",
      "fullname": "",
      "email": "abe-10@spatially.com"
    }
  }

我试过查询:

select * 
from myTable 
where profile['email'] = 'abe-10@spatially.com';

但是什么都没有返回。如何根据 object?

中的电子邮件值提取记录

这不是平面 table,所以这是我展示 table 结构的最佳尝试。第一行是 header,接下来的两行是数据。

    business name | profile:
                    - phone
                    - fullname
                    - email
    -------------------------------------
    "test"       | ""
                   ""
                   "abe-10@spatially.com"
   -------------------------------------
    "other one"  | "(415)884-9938"
                   "Abe Miessler"
                   "abe@test.com"

您编写的示例应该可以运行并且是正确的。

它可能不起作用的原因是 table 架构不正确,特别是:

  • 电子邮件列是使用 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)