Update Big Query Table Schema

2019-02-18 04:21发布

I have a table already in BQ that is populated with data. I want to rename the headings (update the schema) of the table. I'm using command line tool

Presuming it's something along the lines of this??

bq update --schema:Col1:STRING,Col2:STRING....... data_set.Table_Name

But I'm getting

FATAL Flags parsing error: Unknown command line flag 'schema:Col1:STRING,Col2:STRING.....'

What am I missing?

2条回答
何必那么认真
2楼-- · 2019-02-18 05:07

The correct syntax on command line would be

bq update --schema col1:STRING,col2,STRING dataset.table

However, renaming fields is not supported schema change - you will get error message saying

Provided Schema does not match table

You can only add new fields or relax existing fields (i.e. from REQUIRED to NULLABLE).

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-18 05:13

As Mosha says, renaming columns is not supported via API, but you could run a query that scans the whole table and overwrites it.

bq query --nouse_legacy_sql \
 --destination_table p:d.table \
 --replace \
 'SELECT * EXCEPT(col1,col2), col1 AS newcol1, col2 AS newcol2 FROM `p.d.table`'

Warning: This overwrites the table. But that's what you wanted anyways.

查看更多
登录 后发表回答