Bigquery add columns to table schema

前端 未结 5 2037
-上瘾入骨i
-上瘾入骨i 2020-12-01 10:50

I am trying to add new column to BigQuery existing table. I have tried bq command tool and API approach. I get following error when making call to Tables.update().

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 11:47

    I was stuck trying to add columns to an existing table in BigQuery using the Python client and found this post several times. I'll then let the piece of code that solved it for me, in case someone's having the same problem:

    # update table schema
    bigquery_client = bigquery.Client()
    dataset_ref = bigquery_client.dataset(dataset_id)
    table_ref = dataset_ref.table(table_id)
    table = bigquery_client.get_table(table_ref)
    new_schema = list(table.schema)
    new_schema.append(bigquery.SchemaField('LOLWTFMAN','STRING'))
    table.schema = new_schema
    table = bigquery_client.update_table(table, ['schema'])  # API request
    

提交回复
热议问题