Reputation: 4539
I wish to rewrite the values for a text column in a table I have. The particular field has entries like "cat", "dog", "mouse", etc. I wish to rewrite the values in this field as "dog" or "not_a_dog"
Currently I have a query, with commented out portions. I un-comment a line, run it. Comment it back and then un-comment the next line, run it. etc.
I'm sure there is a way to do this programatically.
Here is what I have done so far:
UPDATE some_dataset.some_table SET label='not_a_dog' WHERE label='cat'
#UPDATE some_dataset.some_table SET label='not_a_dog' WHERE label='mouse'
#UPDATE some_dataset.some_table SET label='not_a_dog' WHERE label='moose'
Note I am using standard SQL in BigQuery. I tried playing with a stored procedure but I am not sure if my failure was because I don't really know stored procedures or if they are not compatible with standard SQL in BigQuery on Google Cloud Platform.
Upvotes: 0
Views: 1902
Reputation: 33765
Use an IN list:
UPDATE some_dataset.some_table
SET label='not_a_dog' WHERE label IN ('cat', 'mouse', 'moose')
Upvotes: 4