Bigquery add columns to table schema

前端 未结 5 2038
-上瘾入骨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:33

    In my case I was trying to add a REQUIRED field to a template table, and was running into this error. Changing the field to NULLABLE , let me update the table.

    Also more recent version on updates for anybody stumbling from Google.

    #To create table
    bq mk --schema domain:string,pageType:string,source:string -t Project:Dataset.table
    #Or using schema file
    bq mk --schema SchemaFile.json -t Project:Dataset.table
    
    
    #SchemaFile.json format
    [{                                                                                                                                                                                                                                                
      "mode": "REQUIRED",
      "name": "utcTime",
      "type": "TIMESTAMP"
    },    
    {
      "mode": "REQUIRED",
      "name": "domain",
      "type": "STRING"
    },  
    {
      "mode": "NULLABLE",
      "name": "testBucket",
      "type": "STRING"
    },  
    {
      "mode": "REQUIRED",
      "name": "isMobile",
      "type": "BOOLEAN"                                                                                                                                                                                                                       
    },
    {
      "mode": "REQUIRED",
      "name": "Category",
      "type": "RECORD",
      "fields": [
        {
          "mode": "NULLABLE",
          "name": "Type",
          "type": "STRING"
         },
         {
           "mode": "REQUIRED",
           "name": "Published",
           "type": "BOOLEAN"
         }
        ]
    }]
    
    # TO update
    bq update --schema UpdatedSchema.json -t Project:Dataset.table
    # Updated Schema contains old and any newly added columns 
    

    Some docs for template tables

提交回复
热议问题