0
votes

To find a schema of a BigQuery table, I can use bq show

But bq show will display the the schema info in this format

  • date: string
    |- channel_id: string
    |- video_id: string
    |- asset_id: string
    |- claimed_status: string
    |- uploader_type: string
    |- country_code: string

But what I need is the schema file format that I can just copy and paste to BigQuery Cloud Console to use to create a new table directly.

Such as

channel_id: string, video_id: string, asset_id: string, claimed_status:string, uploader_type: string, country_code: string  

Like MySQL show create table statement, the result of it should be "copy and paste" to create a new table.

Any bq command can do that? I cannot find one.

1

1 Answers

2
votes

You can use

bq --format=prettyjson show 

Example output:

  "schema": {
    "fields": [
      {
        "name": "a", 
        "type": "TIMESTAMP"
      }
    ]
  }, 

And copy the output array to the cloud console:

    [
      {
        "name": "a", 
        "type": "TIMESTAMP"
      }
    ]

For more compact output, you can also use --format=json