1

I have a simple query like this:

SELECT container.category FROM `mybucket` as location
UNNEST location.partsContainers container
WHERE container.category IS NOT null

it gives me json:

[{
    "category": "0028H3:WV CUTTING EDGE AXIAL REAM TRAY"
},
{
    "category": "AVENTURA OASYS 1-2"
}, ... etc.

but what I need it a flat array of strings:

["0028H3:WV CUTTING EDGE AXIAL REAM TRAY",
 "AVENTURA OASYS 1-2",
   ... etc
]

how can I achieve that?

1 Answer 1

3

you can use ARRAY_AGG:

SELECT RAW ARRAY_AGG(container.category)
FROM `mybucket` as location
UNNEST location.partsContainers container
WHERE container.category IS NOT null
Sign up to request clarification or add additional context in comments.

5 Comments

this is close to what I want. It creates an array with an object, with a unnamed key in it, which contains the array I need. How can I make the array to be at the top level? right now it's: [ { "$1": [ "CAT1","CAT2", "etc."
the reason I need it to be completely flat is to be able to merge it (UNION ALL) with another query, and need a flat structure in the end that would cope well with paging (OFFSET and LIMIT)
Have you tried to specify not to return keys in the result, just values?
@user1697575 I'm not sure exactly what you mean
@Agzam, I added the 'RAW' to address your first comment.

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.