Skip to content
Advertisement

Return only ALL CAPS strings in BigQuery

Pretty simple question, specific to BigQuery. I’m sure there’s a command I’m missing. I’m used to using “collate” in another query which doesn’t work here.

     email           
| --------           |
| eric@email.com     | 
| JOHN@EMAIL.COM     | 
| STACY@EMAIL.COM    | 
| tanya@email.com    | 

Desired return:

JOHN@EMAIL.COM,STACY@EMAIL.COM

Advertisement

Answer

Consider below

select *
from your_table
where upper(email) = email           

If applied to sample data in your question – output is

enter image description here

In case you want the output as a comma separated list – use below

select string_agg(email) emails
from your_table
where upper(email) = email

with output

enter image description here

You can use below cte (which is exact data sample from your question) for testing purposes

with your_table as (
  select 'eric@email.com' email union all
  select 'JOHN@EMAIL.COM' union all
  select 'STACY@EMAIL.COM' union all
  select 'tanya@email.com' 
)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement