Bigquery 将 null 注册为 int64

问题描述 投票:0回答:1

在bigquery中,下面提到的查询效果很好:

select 
  col1=col2 as col3 
from (
  select 
    null as col1,
    cast(null as string) as col2  
  union all
    select 
    "abc" as col1,
    "abc" as col2  
)

结果:

col3
1
2 真实

但是如果我将查询修改为:

select 
  col1=col2 as col3 
from (
  select 
    null as col1,
    cast(null as string) as col2  
)

它给了我错误:

No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [2:3] 

为什么子查询中的第一个 null 在这里被视为 int64?

google-bigquery
1个回答
0
投票

BigQuery 根据上下文或周围表达式推断数据类型。 因此,在您的第一个示例中 - 很明显 col1 是一个字符串,因为以下联合了所有值。 在第二个示例中 - 没有任何方法可以识别类型,因此使用默认类型 - 即 int64

© www.soinside.com 2019 - 2024. All rights reserved.