CAST converts a value from one data type to another at query time in BigQuery.
CAST converts values between types so you can compare, join, and aggregate columns that otherwise would be incompatible, all without changing the underlying table schema.
Place CAST(value AS target_type) or use value::target_type inside SELECT, WHERE, JOIN, or GROUP BY clauses. You may also apply SAFE_CAST for NULL-on-error behavior.
Wrap the column with CAST or SAFE_CAST, then use the result in further logic.
SELECT id,
CAST(order_date AS DATE) AS order_dt
FROM Orders
WHERE CAST(order_date AS DATE) > CURRENT_DATE() - INTERVAL 30 DAY;
If customer_id is STRING in Orders but INT64 in Customers, cast one side so they match.
SELECT c.name, o.total_amount
FROM Orders o
JOIN Customers c
ON CAST(o.customer_id AS INT64) = c.id;
Use CAST when mathematical functions require floating-point values.
SELECT id, name,
CAST(price AS FLOAT64) * 1.08 AS price_with_tax
FROM Products;
Prefer SAFE_CAST when data can be dirty, cast columns once in CTEs to avoid repetition, and document any implicit assumptions about formats (e.g., YYYY-MM-DD).
Do not rely on implicit casts—BigQuery performs fewer automatic conversions than PostgreSQL. Also avoid casting inside filters on large tables without using partitions or clustered columns; it can disable pruning.
Use PARSE_* functions for parsing formatted strings (e.g., PARSE_DATE, PARSE_TIMESTAMP) when you need format masks rather than straightforward type conversion.
No. CAST only supports scalar conversions. Use ARRAY or STRUCT constructors instead.
Regular CAST raises an error and aborts the query. SAFE_CAST returns NULL so downstream logic can handle bad rows.
Yes. Given the same input and target type, CAST returns the same output every time.