Get nested data set with all repeated records satisfying condition

Viewed 32

I have a following structure in a BigQuery table:

make        STRING    NOT NULLABLE
feature     RECORD    REPEATED
  name      STRING    REQUIRED

The following query returns all data where at least one feature record satisfies condition length(f.name) = 5:

select * from tbl t, t.feature tf
where length(tf.name) = 5

How do I get only data where ALL feature.name records satisfy the above condition?

1 Answers

Try subquery:

select * from tbl t
where not exists (
    select 1
    from unnest(t.feature) AS tf
    where length(tf.name) != 5
)
Related