skip to Main Content

I have a graph with two vertices, and each contain a property named interests, which is an array of strings. I wanted to compare how many strings both arrays have in common and also if the array contains a certain string.

I have tried the following query, but it throws an error:

SELECT * FROM cypher('QuirkyMatch', $$
        MATCH (v:Person), (user:Person)
        WHERE user.name = 'Sarah' AND v.age > (user.age + 1) AND v.interests CONTAINS 'Art'
        RETURN v
$$) as (potential_match agtype);

ERROR:  agtype string values expected

Here is how I created them:

SELECT * FROM cypher('QuirkyMatch', $$
    CREATE (:Person {
        name: 'Alex',
        age: 27,
        occupation: 'Graphic Designer',
        interests: ['Art', 'Photography', 'Traveling', 'Indies Music'],
        weird_fact: 'I can hold up to 400 straws in my mouth. LOL.'
    }), 
    (:Person {
        name: 'Sarah',
        age: 25,
        occupation: 'Software Engineer',
        interests: ['Hiking', 'Board Games', 'Sci-Fi Movies', 'Dungeons & Dragons', 'Painting', 'Art'],
        weird_fact: 'I collect hot sauces and I have over 50 different ones :)'
    })
$$) as (v agtype);

2

Answers


  1. You can use IN operator for array. Here is how you can achieve the desired output.

    SELECT * FROM cypher('new', $$
            MATCH (v:Person), (user:Person)
            WHERE user.name = 'Sarah' AND v.age > (user.age + 1) AND ('Art' IN v.interests)
            RETURN v
    $$) as (potential_match agtype);
    
    Login or Signup to reply.
  2. Try using the IN keyword instead.

    SELECT * FROM cypher('QuirkyMatch', $$
        MATCH (v:Person), (user:Person)
        WHERE user.name = 'Sarah' AND v.age > (user.age + 1) AND 'Art' IN v.interests
        RETURN v
    $$) as (potential_match agtype);
    

    This answer is 100% my own work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search