安装客户端库
pip install google-cloud-bigquery
示例代码
from google.cloud import bigquery
# 初始化客户端
client = bigquery.Client()
# 表引用
table_ref = client.dataset('dataset_id').table('table_id')
# 获取当前表结构
table = client.get_table(table_ref)
original_schema = table.schema
# 添加新列
new_schema = original_schema[:] # 复制当前表结构
new_schema.append(bigquery.SchemaField("new_column_name", "STRING"))
# 更新表结构
table.schema = new_schema
table = client.update_table(table, ["schema"])
print(f"表结构已更新: {table.schema}")
posted on
浙公网安备 33010602011771号