Reputation: 4618
I'm looking for an option to remove a column from my BigQuery table like ALTER TABLE TABLE_NAME DROP COLUMN_NAME
- but all I found in online was, drop the old table and create a new one.
I'm just wondering, Is there any logical reason not having this option in BigQuery?
Upvotes: 8
Views: 5776
Reputation: 10069
BigQuery now supports DROP COLUMN
ALTER TABLE [[project_name.]dataset_name.]table_name
DROP COLUMN [IF EXISTS] column_name [, ...]
Upvotes: 3
Reputation: 9255
You could remove column via re-writing table.
CREATE OR REPLACE TABLE
temp.table_name AS
SELECT
* EXCEPT (column_name)
FROM
temp.table_name
Upvotes: 4
Reputation: 33705
Dropping a column would mean removing the data from all of the Capacitor files that make up the table, which is an expensive operation. If BigQuery were simply to remove metadata related to the column, you would be charged storage for a phantom column that you can't actually query, which wouldn't be ideal.
When you add a column, conversely, BigQuery treats the missing column in past files as having all NULL
values, which doesn't require modifying them.
There are a couple of different options to remove a column:
Upvotes: 9