Search code examples
postgresqlapache-ageopencypher

Matching within nested list using in Apache AGE?


So I have a list of lists as a property. Like so:

SELECT * FROM cypher('list_test', $$
  CREATE(a: person {nickname: [['thomas', 'tomtom'], ['tom', 'tommy']]})
  RETURN a
$$) as (timothy agtype);

I have tried the following queries:

SELECT * FROM cypher('list_test', $$
  MATCH(name)
  UNWIND(name.nickname) as n
  WHERE 'thomas' in UNWIND(n)
  RETURN nnn
$$) as result;

But I get syntax error with this.

ERROR:  syntax error at or near "WHERE"
LINE 2: MATCH(name) UNWIND(name.nickname) as n WHERE 'thomas' in UNW...

Solution

  • Using WITH, you can manipulate the output before it is passed on to the following query parts. The manipulations can be of the shape and/or number of entries in the result set.

    Try this query:

    SELECT * FROM cypher('list_test', $$
        MATCH (name:person)
        UNWIND name.nickname as n
        WITH n WHERE 'thomas' IN n
        RETURN n
    $$) as (result agtype);