If you have done any programming in the past, I’m sure you’ve heard of the FizzBuzz challenge. This is a simple programming task that’s supposed to catch fresh graduates off guard. There are numerous posts on how to do this in Java, Python, C and so on. But I thought it would be fun to do it in BigQuery.

Image credit: pxfuel


The challenge is the following:

Write a function or procedure that prints the numbers from 1 to 100, but if the number is divisible by 3 print Fizz, if the number is divisible by 5 print Buzz, and if it’s divisible by both 3 and 5 print FizzBuzz.

How exciting, right?

Here’s a Julia version to get us thinking (and because I like Julia):

Now, that this is out of the way, let’s start by creating our numbers. You could use union all statements but that would get very boring very quickly so I’ll use arrays instead. Note that these queries are all free in BigQuery as we’re not querying any actual data, we’re just generating it ourselves on the fly.

This gets us the following:

Image for post

#function #bigquery #fizzbuzz #programming #gcp

FizzBuzz in BigQuery
1.15 GEEK