Google BigQuery:如何使用SQL创建新列

Google BigQuery:如何使用SQL创建新列

问题描述:

我想在不使用旧版SQL的情况下向现有表中添加一列.

I would like to add an column to an already existing table without using legacy SQL.

基本的SQL语法是:

ALTER TABLE table_name
ADD column_name datatype;

我格式化了Google BigQuery的查询格式:

I formatted the query for Google BigQuery:

ALTER TABLE `projectID.datasetID.fooTable`
ADD (barColumn date);

但是语法错误,并出现以下错误:

But than the syntax is incorrect with this error:

Error: Syntax error: Expected "." or keyword SET but got identifier "ADD" at [1:63]

那我该如何正确格式化Google BigQuery的SQL?

So how do I format the SQL properly for Google BigQuery?

BigQuery不支持ALTER TABLE或其他DDL语句,但是您可以考虑

BigQuery does not support ALTER TABLE or other DDL statements, but you could consider submitting a feature request. For now, you either need to open in the table in the BigQuery UI and then add the column with the "Add New Field" button, or if you are using the API, you can use tables.update.