Search code examples
google-bigquerybigquery-udf

Google Big Query: How to alter data type from string to float?


I have the following query and I would like to change the data type for the field "Reach" from string to Float.

The query that I am working on is the following:

SELECT 
  Account,
  Campaign_name,
   Date,
  Impressions,
  Cost__GBP_,
  Link_clicks,
  Ad_set_name,
  Ad_name,
  Reach,   
  Website_conversions   
From 'TableA'

And I am receiving the following Issue: (google big query Could not convert the value to float. Row 8; Col 8)

I have tried to use to amend the query by doing : CAST (Reach AS Float64) As Reach , but it is not working.

Someone can help me with this?

Thank you


Solution

  • SELECT Account, Campaign_name, Date, Impressions, Cost__GBP_, Link_clicks, Ad_set_name, Ad_name, 
      SAFE_CAST(Reach AS FLOAT64) AS Reach, Website_conversions
    From TableA