Array concatenate in n1ql

query
n1ql

#1

Hi everyone I have this query
“select comunidad.nombre
from PPS cam
unnest cam.zona as zona
inner join PPS comunidad on comunidad.id = zona
where cam.id=‘da435348-d467-498b-aec2-e9782b11bca3’ and comunidad.type=‘Comunidad’”
and this is its result:
[
{
“nombre”: “La Esmeralda”
},
{
“nombre”: “Comunidad 1”
}
]
so can I concatenate the name with comma in a only name? example:
[
{
“nombre”: “La Esmeralda, Comunidad 1”
}
]
thanks all.


#2

There is no easy way to do that ( MB-31737). But you like you can follow one described here

SELECT REPLACE(TRIM(ENCODE_JSON(names), "[]\""), "\",\"", ",")
LET  names = ( SELECT RAW comunidad.nombre
               FROM PPS AS cam
               UNNEST cam.zona AS zona
               INNER JOIN PPS AS comunidad ON comunidad.id = zona
               WHERE cam.id="da435348-d467-498b-aec2-e9782b11bca3" AND comunidad.type="Comunidad");

SELECT REPLACE(TRIM(ENCODE_JSON(["abc","def","xyz"]), "[]\""), "\",\"", ",");