I have documents like these:
{
"type": "TYPE_1",
"array": [
{
"field": "A"
},
{
"field": "B"
},
{
"field": "C"
}
]
}
Where every documents of TYPE_1
has the same ordering (A, B, C) but with some exceptions where their sometime “bis fields” like this:
{
"type": "TYPE_1",
"array": [
{
"field": "A"
},
{
"field": "A_BIS"
},
{
"field": "B"
},
{
"field": "C"
}
]
}
I would like to get an array of all the fields
but by keeping the same ordering.
I manage to get all the distinct fields but this is not keeping the order:
SELECT ARRAY_DISTINCT(ARRAY_FLATTEN(ARRAY_AGG(fields), 2)) FROM bucket
LET fields = ARRAY item.field FOR item IN array END
If I’m using only ARRAY_FLATTEN
the ordering is kept but I then have all the duplicates. Any idea on how to solve this?