Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery - set "" as Null

I get csv files where string null value expressed as "", when I load the file to BigQuery the value of the field is empty string and not Null.

Is there a way to set BigQuery to see "" as Null value?

like image 317
Aviv Noy Avatar asked Mar 01 '16 07:03

Aviv Noy


2 Answers

Adding this for those who might still need it. There is a NULLIF function that can do this easily.

NULLIF(column_name,'')

What this does is if column_name is an empty string i.e. '', it puts NULL, if not, it puts the column_name value.

like image 152
Kay Avatar answered Nov 18 '22 03:11

Kay


It seems to me that it might be easiest to simply remove all instances of "" from the original file. (Through find and replace.)

Otherwise, once you have loaded the table into BigQuery, you could select all columns, apply case when column_name = '' then null else column_name end to the relevant column, and save the results as a new table.

like image 36
oulenz Avatar answered Nov 18 '22 04:11

oulenz