【问题标题】:Can you bulk import in crateDB in a table with an array of objects column?您可以在带有对象列数组的表中批量导入 crateDB 吗?
【发布时间】:2019-06-28 08:02:48
【问题描述】:

所以我运行 CrateDB 3.3.3 并且我有一个表,其中有一列类型为对象数组的列

CREATE TABLE IF NOT EXISTS "doc"."testarray" (
"id" INTEGER,
"myarraycol" ARRAY(OBJECT (DYNAMIC) AS (
  "avg" DOUBLE,
  "eventconditiondefid" INTEGER,
  "max" DOUBLE,
  "min" DOUBLE
))
)

我已经知道如何在其中插入一行

insert into testarray (id, myarraycol) values (2, [{"min"=2,"max"=3,"avg"=0.5,"eventconditiondefid"=123},{"min"=0,"max"=1,"avg"=0.5,"eventconditiondefid"=456}]);

但是,在我的应用程序中,我通过 HTTP 端点将数据批量插入 CrateDB。

https://crate.io/docs/crate/reference/en/latest/interfaces/http.html

我让它适用于常规表,但不能使它适用于具有一列对象数组的表。谁能告诉我如何使批量插入与这些类型的列一起使用?我似乎找不到任何关于它的示例或文档。

{ "stmt":"INSERT INTO testarray (  id, myarraycol) VALUES (  ?,   ?) ","bulk_args":[[1,[{"min"=0.616523,"max" = 1.10974,"Avg" = 0.874692,"EventConditionDefId" = 505}]]]}

(上述批量插入代码失败,返回(400)错误请求)

【问题讨论】:

    标签: cratedb


    【解决方案1】:

    问题是JSON应该是这样的:

    { "stmt":"INSERT INTO testarray (id, myarraycol) VALUES (?,?) ","bulk_args":[[1,[{"min":0.616523,"max" : 1.10974,"Avg" : 0.874692,"EventConditionDefId" : 505}]]]}
    

    【讨论】:

    • 您知道是否可以在对象数组上使用“ANY”运算符吗? crate.io/docs/crate/reference/en/latest/general/dql/…
    • SELECT * FROM testarray WHERE ANY(myarraycol['EventConditionDefId'])=505 此查询不起作用,它返回“SQLActionException[SQLParseException: 第 5:5 行:输入时没有可行的替代方案”
    • 您需要将那里的语法倒置如下:SELECT * FROM testarray WHERE 505 = ANY(myarraycol['EventConditionDefId']);
    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 2022-06-10
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    相关资源
    最近更新 更多