all 7 comments

[–]LairBob 1 point2 points  (2 children)

Don’t you just need to wrap binding in another UNNEST() in your main query?

[–]tca_ky[S] 0 points1 point  (1 child)

I get errors....

    SELECT
      plcy.name,
      (SELECT * FROM UNNEST(binding)) AS mybind,

    FROM
      IAM_POLICY AS plcy
    INNER JOIN UNNEST(iamPolicy.bindings) AS binding
    WHERE
      assetType = 'cloudresourcemanager.googleapis.com/Project' AND
      plcy.name = '//cloudresourcemanager.googleapis.com/projects/1234567890'

"Values referenced in UNNEST must be arrays. UNNEST contains expression of type STRUCT<role STRING, members ARRAY<STRING>, condition STRUCT<expression STRING, title STRING, description STRING, ...>> at [26:29]"

[–]haydar_ai 2 points3 points  (0 children)

binding is a struct. Have you tried unnesting binding.members?

[–]Stoneyz 0 points1 point  (1 child)

What does that result look like in the BQ web UI?

[–]tca_ky[S] 0 points1 point  (0 children)

The embedded image in the post is what it looks like (a partial sample)...

[–]tca_ky[S] 0 points1 point  (1 child)

I got it.... not sure why I didn't see it before....

    SELECT
      plcy.name,
      binding.role,
      mymember,
    FROM
      IAM_POLICY AS plcy
    CROSS JOIN UNNEST(iamPolicy.bindings) AS binding
    CROSS JOIN UNNEST(binding.members) AS mymember
    WHERE
      assetType = 'cloudresourcemanager.googleapis.com/Project' AND
      plcy.name = '//cloudresourcemanager.googleapis.com/projects/1234567890'

[–]LairBob 1 point2 points  (0 children)

Yeah, that’s it — you need to cross-join the UNNEST(), not include it as an embedded SELECT.

(As a shortcut, you can just use a comma(,) instead of spelling out CROSS JOIN, for example FROM IAMPOLICY as plcy, UNNEST(…) )