插入Clickhouse jsoneachrow嵌套

发布于 2025-02-03 10:36:30 字数 556 浏览 2 评论 0原文

我有下表,

SET flatten_nested = 0;
CREATE TABLE test.hm
(
    customDimensions Array(Nested(index Nullable(Int64), value Nullable(String)))
)
    engine = Memory;

我想在以下查询中插入其中:

INSERT INTO test.hm FORMAT JSONEachRow {"customDimensions": [{"index": 1, "value": 2}]}

但是它失败了

代码:130,e.displayText()= db ::异常:数组不会以'[''trace :(阅读键customDimensions的值)开头:(在第1行1)(版本21.8.4.51(官方)构建))

如何将其修复并插入jsonflatten_nested = 0具有多LVL嵌套层次结构?

I have the following table

SET flatten_nested = 0;
CREATE TABLE test.hm
(
    customDimensions Array(Nested(index Nullable(Int64), value Nullable(String)))
)
    engine = Memory;

I am trying to insert into it with the following query:

INSERT INTO test.hm FORMAT JSONEachRow {"customDimensions": [{"index": 1, "value": 2}]}

But it fails with

Code: 130, e.displayText() = DB::Exception: Array does not start with '[' character: (while reading the value of key customDimensions): (at row 1) (version 21.8.4.51 (official build))

How to fix it and insert JSON into flatten_nested = 0 having multi lvl nested hierarchy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2025-02-10 10:36:30

(嵌套因为它是二维数组吗

您确定

insert into test.hm values([[(1,'test1'), (2,'test2')]]);

select * from test.hm format JSONEachRow;
{"customDimensions":[[["1","test1"],["2","test2"]]]}

需要阵列 ,值nullable(string)))

,您可以使用jsonextract

https://kb.altinity.com/altinity-kb-schema-design/altinity--kb-jsonasstring-and.-kb-jsonasstring-and.-mat--- json-parser/

https://kb.altinity.com/altinity-kb-queries-and-syntax/jsonextract-to-parse-parse-parse-many-atributes-attributes-attributes-at-a time/

or 或 htttps:htttps:htttps:// click lickhouse .com/docs/en/guides/developer/working-with-json/json-semi-structured/#json-object-type

Are you sure you need Array(Nested because it's two-dimensional array.

you can use select to get understanding what JSONEachRow CH expectes

insert into test.hm values([[(1,'test1'), (2,'test2')]]);

select * from test.hm format JSONEachRow;
{"customDimensions":[[["1","test1"],["2","test2"]]]}

I guess you really need Array(Tuple(index Nullable(Int64), value Nullable(String)))

And you can use JSONExtract

https://kb.altinity.com/altinity-kb-schema-design/altinity-kb-jsonasstring-and-mat.-view-as-json-parser/

https://kb.altinity.com/altinity-kb-queries-and-syntax/jsonextract-to-parse-many-attributes-at-a-time/

Or https://clickhouse.com/docs/en/guides/developer/working-with-json/json-semi-structured/#json-object-type

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文