Split Strings in Bigquery Using REGEXP
Assume that we have a bigquery column with values like below:
---------------------------------------------------------
pair
----------------------------------------------------------
television:100
mobile:250
driver: 110
----------------------------------------------------------
Expected Output
---------------------------------------------------------
Device | Cost
---------------------------------------------------------
television |100
mobile | 250
driver | 110
----------------------------------------------------------
Use below bigquery statements to split the column:
CASE
WHEN REGEXP_MATCH(pair,":") THEN REGEXP_EXTRACT(pair, r'(\w*):')
ELSE pair
END AS attribute_name,
REGEXP_EXTRACT(pair, r'\:(.*)') AS attribute_value
Assume that we have a bigquery column with values like below:
---------------------------------------------------------
pair
----------------------------------------------------------
television:100
mobile:250
driver: 110
----------------------------------------------------------
Expected Output
---------------------------------------------------------
Device | Cost
---------------------------------------------------------
television |100
mobile | 250
driver | 110
----------------------------------------------------------
Use below bigquery statements to split the column:
CASE
WHEN REGEXP_MATCH(pair,":") THEN REGEXP_EXTRACT(pair, r'(\w*):')
ELSE pair
END AS attribute_name,
REGEXP_EXTRACT(pair, r'\:(.*)') AS attribute_value
No comments:
Post a Comment