jsonextractInt64从字符串中提取到clickhouse
我有一个源表:
CREATE TABLE test.source
(
text_json String
)
engine = Memory;
我有一个目标表:
CREATE TABLE test.destination
(
column Nullable(Int64)
)
engine = Memory;
我插入到源: 插入test.source(text_json)格式JSONASSTRING {“ column”:null};
然后,我尝试将JSON int值解析并插入目标中
INSERT INTO test.destination (column)
SELECT JSONExtractInt(text_json) FROM test.source;
,但是它将插入0。 - 确定性的行为好像我事先具有真正的零一样,将不可能区分null
和0
。 > null ?
I have a source table:
CREATE TABLE test.source
(
text_json String
)
engine = Memory;
I have a destination table:
CREATE TABLE test.destination
(
column Nullable(Int64)
)
engine = Memory;
I insert to the source:INSERT INTO test.source (text_json) FORMAT JSONAsString {"column": null};
Then I try to parse json int value and insert into destination
INSERT INTO test.destination (column)
SELECT JSONExtractInt(text_json) FROM test.source;
However, it will insert 0. And it will be a non-deterministic behavior as if I have a real zero beforehand, it will be impossible to differentiate between NULL
and 0.
How to parse from JSONString
null value into Int64 column AS Null
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 json_value 提取字符串值并将其传递给插入(带有隐式或显式铸造):
结果将为null:
You can use JSON_VALUE to extract the string value and pass that to INSERT instead (with implicit or explicit casting):
The result will be NULL:
关于
JSON_VALUE
,似乎在以后的版本中更改了。我在23.8.16进行了测试,但没有返回nulls:对我有用的是
jsonextract
:Regarding the
JSON_VALUE
, seems like it was changed in later versions. I tested on 23.8.16 and it didn't return NULLs:What worked for me was
JSONExtract
: