Skip to main content

Command Palette

Search for a command to run...

A closer look at STRING_AGG in BigQuery

Updated
1 min read
A closer look at STRING_AGG in BigQuery
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Modern SQL engines have a wealth of aggregation functions.

Here's a quick example that makes use ofBigQuery STRING_AGG.

What does it do?

It aggregates all the values in a grouping, joined by a separator of our choice, creating a string of those joined values.

We can of course choose to:

➡️ keep only distinct values, as well as
➡️ order the values in the newly created string

so that, as in the below example, ("Card", "Cash") and ("Cash", "Card") both produce "Card~Cash", every time.

Any interesting aggregation function that you use in your SQL dialect?

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.

More from this blog

D

Datawise — SQL, BigQuery & Python for Data Engineers

205 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.