Split to array in n1ql

Hi everyone I need to do a split to array but I don’t know how do it.
this is my json i try to do it this=
“select split(idResguardos,’+’)[0] from PPS where titulo=‘Campaña octubre’” but not work
[
{
“idResguardos”: [
“04a03880-28b5-4ca1-adc3-100f224cbeb0+5213c7ad-c63b-47f8-89bc-e1c14138578b+00adf216-d8b9-4c8a-9973-93e07238be33+5770c34f-ef75-46ce-8840-afefc9450de8”,
“04a03880-28b5-4ca1-adc3-100f224cbeb0+5213c7ad-c63b-47f8-89bc-e1c14138578b+00adf216-d8b9-4c8a-9973-93e07238be33+5770c34f-ef75-46ce-8840-afefc9450de8”
],
“titulo”: “Campaña octubre”
}
]
thanks.

Split on what basis. Post expected output will help.

Gives 0 element

SELECT idResguardos[0] 
FROM PPS 
WHERE titulo="Campaña octubre";

Gives First 5 elements

  SELECT idResguardos[0:5] 
    FROM PPS 
    WHERE titulo="Campaña octubre";

https://blog.couchbase.com/working-json-arrays-n1ql/

I need to do split with ‘+’ a one each idResguardos for get all diferents ids that are in each idResguardo

SELECT  ARRAY_FLATTEN(ARRAY SPLIT(v,"+") FOR v IN idResguardos END,2) 
FROM RPS 
WHERE ......;

For Distinct values

SELECT  ARRAY_DISTINCT(ARRAY_FLATTEN(ARRAY SPLIT(v,"+") FOR v IN idResguardos END,2)) 
FROM RPS 
WHERE ......;
1 Like

thank you bro works :slight_smile:
can you say me what do ‘for’ in the sentence

It is looping construct

ARRAY, FIRST, and OBJECT

Range transforms (ARRAY, FIRST, OBJECT) allow you to map and filter the elements or attributes of a collection or object(s). ARRAY evaluates to an array of the operand expression, while FIRST evaluates to a single element based on the operand expression. OBJECT evaluates to an object whose name : value attributes are name-expr : expr .

Name-expr must evaluate to a string. If not, that attribute is omitted from the result object.

range-xform:

1 Like