使用 crate 的 HTTP API 插入对象数组:错误 4003

Using crate's HTTP API to insert an array of objects : error 4003

我正在尝试使用 Crate 的 2.1.8 HTTP 端点插入一行,但它系统地失败并出现错误 4003: 我的 table 包含一个对象数组列,它失败并显示错误 4003:“SQLActionException[ColumnValidationException: Validation failed for arr: '[{\“t\“:1}, {\“z\“ :\“foo\“}]' 无法转换为类型 object_array]”

这是 table 的创作: 如果不存在,则创建 TABLE “doc”.“test” ( “arr”数组(对象(动态)), “姓名”STRING )

现在这是我的 json :

{“stmt”:“插入\“测试\”(\“名称\“,\“arr\“)值(?,?)“,“args”:[“测试”,“[ {\“t\“:1}, {\“z\“:\“foo\“}]“]}

和我对 post 请求的命令:wget --header “Content-Type: application/json” --post-file query_test.json -O - ' http://localhost:4200/_sql?types&error_trace=true'

结果是: 4003:“SQLActionException[ColumnValidationException:arr 的验证失败:'[{\“t\“:1}, {\“z\“:\“foo\“}]' 无法转换为类型 object_array] ”

如果我 运行 从 Web 控制台执行此操作:INSERT INTO “test” (“name”,“arr”) VALUES ('test', [{“t”=1}, {“z ”='foo'}]); 它工作正常......知道我做错了什么吗?

只需删除数组参数值周围的引号,不要转义数组中的引号,例如:

{"stmt":"INSERT INTO \"test\" (\"name\",\"arr\") VALUES (?,?)", "args":["test", [{"t":1}, {"z":"foo"}]]}

否则它是 JSON 字符串值而不是数组,因此 CrateDB 会将其解释为字符串。