MD Sanim Iqbal
MD Sanim Iqbal

Reputation: 31

How to add calculated column in bigquery data table?

I am using the below code:

ALTER TABLE `trim-opus-308402.Covid_Dataset_SQL_Practice_24May21.Percentage vaccine`
ADD COLUMN Vaccine_Coverage numeric AS  ((Rolling_vaccination / population)*100)

I am getting error message:

ALTER TABLE ADD COLUMN does not support generated columns yet at [2:12]

Upvotes: 3

Views: 4927

Answers (1)

Cylldby
Cylldby

Reputation: 1978

You can add an empty column to your schema using this syntax, but I don't think you can fill it in the same operation. You might consider a two step approach:

ALTER TABLE `trim-opus-308402.Covid_Dataset_SQL_Practice_24May21.Percentage vaccine`
ADD COLUMN Vaccine_Coverage NUMERIC;

UPDATE `trim-opus-308402.Covid_Dataset_SQL_Practice_24May21.Percentage vaccine`
SET Vaccine_Coverage = (Rolling_vaccination / population)*100
WHERE TRUE;

Upvotes: 2

Related Questions