-
W3Schools has a good page that talks about ways to create tables. Since I already went through how to make a new dataset (with a schema) in “Setting up Dataset” drop down section, here I wanted to go through creating a new table (from an existing one) and changing some data types.
To create a new table from an existing one, use “AS” and “SELECT” what you want “FROM” an existing table.
In BigQuery you can use the SAFE prefix. According to the documentation: if you begin a function with the SAFE. prefix, it will return NULL instead of an error.
Here is the sample code from my school board achievement and progress table:
CREATE TABLE
school_board.achievement_progress AS
SELECTp.Board_Number AS board_number,FROM
p.Board_Name AS board_name,
SAFE_CAST(p.Grade_6_EQAO_Reading_Results AS FLOAT64)*100 AS grade_6_EQAO_reading_results_percent,
SAFE_CAST(p.Progress_in_Grade_6_EQAO_Reading_Results AS FLOAT64)*100 AS progress_in_grade_6_EQAO_reading_results_percent,
p.Extract_Date AS extract_dateschool_board.progress pAs you may have noticed, I chose to shorten the name of my previous table to “p” to make it simpler to reference the columns I wanted.