You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BigQuery表连接报错:INT64与ARRAY<INT64>类型不匹配求解

Fixing INT64 vs ARRAY Mismatch in BigQuery Joins

Hey there! Let's sort out this join issue you're facing—coming from Postgres, BigQuery's array handling has a few syntax quirks that can trip you up at first. The error you're seeing makes total sense: you can't directly compare a scalar INT64 value to an ARRAY<INT64> using =; BigQuery needs explicit logic to check if the scalar exists within the array.

Here are two solid solutions depending on your use case:

1. Unnest the Array (for row-level matching)

If you need to create a separate row for every element in c.vid that matches d.associations.associatedvids, use UNNEST to expand the array into individual scalar values:

SELECT *
FROM your_table_c c
CROSS JOIN UNNEST(c.vid) AS unnested_vid
JOIN your_table_d d
  ON unnested_vid = d.associations.associatedvids

This works similarly to unnesting arrays in Postgres, but BigQuery requires explicitly joining the unnested values with CROSS JOIN UNNEST. Each element in c.vid becomes its own row, so you'll get one row per matching array element.

2. Check Array Membership (without unnesting)

If you don't want to split rows and just need to verify that d.associations.associatedvids exists inside c.vid, use either the IN operator with UNNEST or the built-in ARRAY_CONTAINS function:

Option A: Using IN UNNEST()

SELECT *
FROM your_table_c c
JOIN your_table_d d
  ON d.associations.associatedvids IN UNNEST(c.vid)

This is the BigQuery equivalent of Postgres' = ANY(c.vid) syntax, adapted to the platform's requirements.

Option B: Using ARRAY_CONTAINS()

SELECT *
FROM your_table_c c
JOIN your_table_d d
  ON ARRAY_CONTAINS(c.vid, d.associations.associatedvids)

This is a clean, BigQuery-native function that explicitly checks if the scalar value is present in the array. It's perfect for straightforward membership checks without row splitting.

Just pick the approach that aligns with what you need from your join results—both will resolve the type mismatch error you're seeing.

内容的提问来源于stack exchange,提问作者Tajs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 12:57:42