Created
June 23, 2020 03:43
-
-
Save gecko655/f7ff4ac727c71692e3b83a5917c1bbb4 to your computer and use it in GitHub Desktop.
BigQuery union behavior with different column definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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