Skip to content

Instantly share code, notes, and snippets.

@gecko655
Created June 23, 2020 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gecko655/f7ff4ac727c71692e3b83a5917c1bbb4 to your computer and use it in GitHub Desktop.
Save gecko655/f7ff4ac727c71692e3b83a5917c1bbb4 to your computer and use it in GitHub Desktop.
BigQuery union behavior with different column definition
create table `uniontest.uniontest_1`
(partition_key date, cluster_key string, hoge string)
partition by partition_key
cluster by cluster_key
as select cast('2020-06-22' as date), 'a', 'b';
create table `uniontest.uniontest_2`
(partition_key date, cluster_key string, piyo string)
partition by partition_key
cluster by cluster_key
as select cast('2020-06-23' as date), 'c', 'd';
-- Now, uniontest_1 is:
-- +---------------+-------------+------+
-- | partition_key | cluster_key | hoge |
-- +---------------+-------------+------+
-- | 2020-06-22 | a | b |
-- +---------------+-------------+------+
-- uniontest_2 is:
-- +---------------+-------------+------+
-- | partition_key | cluster_key | piyo |
-- +---------------+-------------+------+
-- | 2020-06-23 | c | d |
-- +---------------+-------------+------+
select *
from `uniontest.uniontest_*`
-- This query returns:
-- +---------------+-------------+------+
-- | partition_key | cluster_key | piyo |
-- +---------------+-------------+------+
-- | 2020-06-22 | a | NULL |
-- | 2020-06-23 | c | d |
-- +---------------+-------------+------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment