Hi,
I have multiple documents that have an array of strings such that when I select out all of the documents based on the WHERE condition, the result separates the output for each document.
For example, I have two documents resulting from the query:
"results": [
{
"$1": [
"abc",
"def"
]
},
{
"$1": [
"xyz"
]
}
],
A sample query could look like:
select myString from bucket where myValue in [1, 2];
What if I want to combine the result together? so that it would look like this:
"results": [
{
"$1": [
"abc",
"def",
"xyz"
]
}
],
I seem to have gotten it to work by using UNNEST and then ARRAY_AGG. I just want to make sure that I’m on the right track…
select array_agg(s) from bucket b unnest b.myArray s where b.myValue in [1, 2];
Now I want to take the output (e.g., the above) and rewrite the query so that it would use the values (e.g., like an in-line view from Oracle). This is how I would write it out before using the in-line view:
select count(*) from bucket where aValue in ["abc", "def", "xyz"];
How would I use it as a nested N1QL (if that’s possible)? When I try to place the original N1QL after the IN in round brackets ( … ), I don’t get any error but the result is wrong.
select count(*) from bucket where aValue in (select array_agg(s) from bucket b unnest b.myArray s where b.myValue in [1, 2]);
Thank you.
Regards, Steve