Home > Software design >  Alter column in BigQuery correcting typo
Alter column in BigQuery correcting typo

Time:09-22

I have a table in BigQuery with a typo:

id,typo_column
1,Unknown
2,Unknown
3,Uknown

I want to replace Uknown by Unknown. Is there an easy way to do this in BigQuery?

CodePudding user response:

You can use DML to fix all entries with typos:

UPDATE yourproject.yourdatabase.yourtablewithtypo
SET typo_column = REGEXP_REPLACE(typo_column, r"(Uknown)", "Unknown")
WHERE TRUE

See the docs for a more complete example.

CodePudding user response:

You would normally do this as:

UPDATE yourproject.yourdatabase.yourtablewithtypo
    SET typo_column = 'Unknown'
    WHERE typo_column = 'Uknown';

There is no need to update every row in the table. There is no need to use regular expressions, and there is no need to run logic for replacement on rows that don't have the incorrect value.

  • Related