cancel
Showing results forΒ
Did you mean:Β

## Cypher's filter is not supported

Node Clone

I have e problem with 'filter'. It is no supported .

Query is a part from "GraphGist - Information Flow Through a Network"

##### Query 4
``````// Find all unique, simple paths from one city to another
MATCH p=(:City { name: "Tokyo" })-[:BACKBONE_TO*]-(:City { name: "Chicago" })
WHERE all(c IN nodes(p) WHERE 1=length(filter(m IN nodes(p) WHERE m=c)))
RETURN DISTINCT extract(n IN nodes(p) | n.name) AS Path, length(p) AS Length
``````

## Filter is no longer supported. Please use list comprehension instead (line 2, column 40 (offset: 118)) "WHERE all(c IN nodes(p) WHERE 1=length(filter(m IN nodes(p) WHERE m=c)))"

How to transform it to working query ?

1 ACCEPTED SOLUTION
Ninja

Why is there a `RETURN` in your `WHERE` clause?

7 REPLIES 7
Ninja

Hello @ilko.k.v

You must use a comprehension list:

``````// Find all unique, simple paths from one city to another
MATCH p=(:City {name: "Tokyo"})-[:BACKBONE_TO*]-(:City {name: "Chicago"})
WHERE all(c IN nodes(p) WHERE 1=size([m IN nodes(p) WHERE m=c]))
RETURN DISTINCT [n IN nodes(p) | n.name] AS Path, length(p) AS Length
``````

Regards,
Cobra

Node Clone

I try with

MATCH p=(:City { name: "Tokyo" })-[:BACKBONE_TO*]-(:City { name: "Chicago" })
WHERE all(c IN nodes(p) WHERE 1=length(RETURN[m IN nodes(p) WHERE m=c]))
RETURN DISTINCT extract(n IN nodes(p) | n.name) AS Path, length(p) AS Length

But return error:
Invalid input 'WHERE': expected
"OR"
"XOR"
"AND"
"=" ...

Ninja

There is no `extract` in the query I gave you. I also replaced it with a comprehension list.

Node Clone

Error is coming from "WHERE 1="

Ninja

Why is there a `RETURN` in your `WHERE` clause?

Node Clone

Thank you Cobra

Working

MATCH p=(:City { name: "Tokyo" })-[:BACKBONE_TO*]-(:City { name: "Chicago" })
WHERE all(c IN nodes(p) WHERE 1=size([m IN nodes(p) WHERE m=c]))
RETURN DISTINCT [n IN nodes(p) | n.name] AS Path, length(p) AS Length

The Graph Gist Example should be updated now. Thanks for raising it.

Nodes 2022

NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Neo4j Resources