1

I'm trying to find all instances of rows where one of the array items contains a value, ignoring the case in Google BigQuery.

I'm able to do this:

SELECT
  COUNT(*)
FROM
  `my_bq_project.my_bq_dataset.my_table`
WHERE
  (
      'AAA' IN UNNEST(array_1.array_2.some_text)
  )

This works well for finding 'AAA' inside array_1.array_2.some_text. But I would like to also find 'aaa', 'Aaa', and so forth.

But this does not work:

SELECT
  COUNT(*)
FROM
  `my_bq_project.my_bq_dataset.my_table`
WHERE
  (
      'AAA' IN UNNEST(LOWER(array_1.array_2.some_text))
  )

And I would like to refrain from duplicating the where statement (adding where conditions for 'AaA', 'aaa', etc.).

Is there a way to apply string functions like LOWER on struct fields that are in arrays in BigQuery SQL?

Thanks

1 Answer 1

2

Try below approach

SELECT
  COUNT(*)
FROM
  `my_bq_project.my_bq_dataset.my_table`
WHERE LOWER('AAA') IN (
  SELECT LOWER(some_text)
  FROM UNNEST(array_1) a, UNNEST(a.array_2)
)
Sign up to request clarification or add additional context in comments.

1 Comment

glad it worked for you. consider also voting up the answer then :o)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.