Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why BigQuery doesn't have an option to remove column?

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?

like image 554
Vijin Paulraj Avatar asked Aug 22 '17 11:08

Vijin Paulraj


People also ask

Can you delete columns in BigQuery?

BigQuery has supported Data Manipulation Language (DML) functionality since 2016 for standard SQL, which enables you to insert, update, and delete rows and columns in your BigQuery datasets.

What is BigQuery not good for?

You need to understand that BigQuery cannot be used to substitute a relational database, and it is oriented on running analytical queries, not for simple CRUD operations and queries.


2 Answers

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:

  • Select from the original table, excluding the column that you don't want to keep. Then copy the resulting table and overwrite the original one.
  • Create a logical view over the table with the columns that you want. Now query the logical view instead of the table--you can make other "modifications" as well such as casting or filtering without having to touch the underlying table. The downside is that you will be charged for the old column that you don't need to query any more, however.
like image 137
Elliott Brossard Avatar answered Oct 16 '22 18:10

Elliott Brossard


You could remove column via re-writing table.

CREATE OR REPLACE TABLE
  temp.table_name AS
SELECT
  * EXCEPT (column_name)
FROM
  temp.table_name
like image 32
northtree Avatar answered Oct 16 '22 18:10

northtree