Big Query Create or Replace table mysteriously fails when clustering or partitioning is changed

This Big Query script will fail

create or replace table joel_dataset.demo_table (
  int_field INT64,
  int_field2 INT64,
  changed_time TIMESTAMP,)
partition by range_bucket(
            int_field,
            generate_array(0, 10, 1)
        )
;

create or replace table joel_dataset.demo_table (
  int_field INT64,
  int_field2 INT64,
  changed_time TIMESTAMP,)
partition by range_bucket(
            int_field,
            generate_array(0, 10, 1)
        )
cluster by int_field2 --adding clustering
;


Invalid value: Incompatible table partitioning specification. Expected partitioning specification range(type:integer,field:int_field,start:0,end:10,interval:1) clustering(int_field2), but input partitioning specification is range(type:integer,field:int_field,start:0,end:10,interval:1) at [2:1]

The reason seem to be that "or replace" does not work. Big Query evaluates any preexisting table and crashes if you change anything.
It will also fail with mysterious erro if a view exists with the same name.

This Big Query script will work


drop table if exists joel_dataset.demo_table;
create or replace table joel_dataset.demo_table (
  int_field INT64,
  int_field2 INT64,
  changed_time TIMESTAMP,)
partition by range_bucket(
            int_field,
            generate_array(0, 10, 1)
        )
;

drop table if exists joel_dataset.demo_table;

create or replace table joel_dataset.demo_table (
  int_field INT64,
  int_field2 INT64,
  changed_time TIMESTAMP,)
partition by range_bucket(
            int_field,
            generate_array(0, 10, 1)
        )
cluster by int_field2
;

Comments

Popular posts from this blog

SSIS: Set parent package variable from child package

How to decrypt stored password from SSMS registered servers

Insert bulk statement does not support recompile (SQL 2017)