How do i append query results to create new columns in dataset on bigquery?

Viewed 27

Would like to alter my original dataset to include the results from the query. Currently year and month are connected, would like to split the string and append the results to the original dataframe

1 Answers

I see that you are sourcing the value for your new column from your own source table.

You can do it two ways:

Idea1:

Let's say you have a table with columns:

col1, col2

and you want to add col3, you can always do something like:

CREATE OR REPLACE table your_source_table as     
select col1, col2, (your_calculation_for_col3) as col3 from your_source_table 

Idea 2:

Add a new column to your table and update value of it like below:

ALTER TABLE your_source_table
ADD COLUMN COL3 DATA_TYPE_FOR_COL3;

UPDATE your_source_table 
SET col3 = your_new_calculated_value
WHERE TRUE;

see if any of this helps.

Related