gpt4 book ai didi

sql - ClickHouse:0 是 Null?

转载 作者:行者123 更新时间:2023-12-05 02:42:43 26 4
gpt4 key购买 nike

create database test

create table test.A (id UInt8, data String) engine MergeTree() order by (id)

create table test.B (id UInt8, data String) engine MergeTree() order by (id)

insert into test.A values (0,'a'),(1,'b'),(2,'c')

insert into test.B values (1,'x'),(2,'y'),(3,'z')
select *, isNull(a.id), isNull(b.id) from test.A a full join test.B b on a.id = b.id

enter image description here

如何理解0是0还是0是Null?

最佳答案

问题在于如何处理外连接。根据文档,这使用设置 join_use_nulls :

Sets the type of JOIN behaviour. When merging tables, empty cells may appear. ClickHouse fills them differently based on this setting.

Possible values:

0 — The empty cells are filled with the default value of the corresponding field type.1 — JOIN behaves the same way as in standard SQL. The type of the corresponding field is converted to Nullable, and empty cells are filled with NULL.

Default value: 0.

换句话说,默认方法是不符合 SQL 的。就个人而言,我认为这样的默认值没有用。我猜 Clickhouse 对 NULL 值有强烈的反感。

因此,您可以改为检查 a.id = b.id 以查看是否存在匹配项。

关于sql - ClickHouse:0 是 Null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67315934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com