BigQuery: IFNULL after an UPDATE column, then "LIV"

66 views Asked by At

Im new in all of this and Im having a dificult time doing the following: After an Alter Table where Im adding a new column Im updating the values based on another column. What a want to do is where there is a null after the process put the name "LIV".

How would you do it?

Thanks in advance

Code:

ALTER TABLE TEST1 ADD COLUMN UBIC2 STRING;
UPDATE TEST1 
SET UBIC2 = UBIC
WHERE ZONA ="X1" or ZONA ="X2"

Tried to use an IFNULL(UBIC2, "LIV")

2

There are 2 answers

1
Mureinik On

You could update the table with a case expression. Also, since you want to update all the rows of the table, you can lose the where clause:

UPDATE test1
SET    ubic2 = CASE WHEN zona IN ('X1', 'X2') THEN ubic ELSE 'LIV' END
0
Mr.Batra On

Tried this ?

UPDATE test1
SET    ubic2 = CASE WHEN zona IN ('X1', 'X2') THEN ubic ELSE 'LIV' END
where 1=1