0

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...
RU-D
  • 224
  • 8

2 Answers2

0

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);
Mohayu Din
  • 433
  • 9
0

According to the documentation, you have to use agtype as the type returned by AGE. Also, to return the nickname list as individual rows you must use UNWIND twice as a command, without the (). Finally, you have to use WITH clause with WHEREclause.

Use this query:

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


To return:

    n     
----------
 "thomas"
 "tomtom"
 "tom"
 "tommy"
(4 rows)
Carla
  • 326
  • 1
  • 7