Search code examples
postgresqlcypherapache-ageopencypher

Appending data to an array


I created a vertex with a property called interests and it should store an array of strings.

SELECT * FROM cypher('DatingApp', $$
    CREATE (v:Person {
        name: 'Alex',
        age: 27,
        occupation: 'Graphic Designer',
        interests: []
    })
    RETURN v
$$) as (v agtype);

How can I add more strings to this property with another query?


Solution

  • You can use this code:

    SELECT * FROM cypher('DatingApp', $$
        MATCH (v:Person { name: 'Alex' }) 
        SET v.interests = v.interests + ['soccer', 'car racing']
        $$) as (v agtype);
    

    Please note that this operation does not check whether the data being appended already exists in the array.