BigQuery pipe syntax: A much cleaner way to write SQL
cloud.google.com
cloud.google.com
Examples:
-- Standard Syntax SELECT AVG(num_trips) AS avg_trips_per_year, payment_type
FROM
(
SELECT EXTRACT(YEAR FROM trip_start_timestamp) as year,
payment_type, COUNT() AS num_trips
FROM `bigquery-public-data.chicago_taxi_trips.taxi_trips`
GROUP BY year, payment_type
)
GROUP BY payment_type
ORDER BY payment_type;
Here’s that same query using pipe syntax — no subquery needed!
-- Pipe Syntax FROM `bigquery-public-data.chicago_taxi_trips.taxi_trips`
|> EXTEND EXTRACT(YEAR FROM trip_start_timestamp) AS year
|> AGGREGATE COUNT() AS num_trips
GROUP BY year, payment_type
|> AGGREGATE AVG(num_trips) AS avg_trips_per_yearGROUP BY payment_type ASC;