Filtering nodes by number of children?

111 views
Skip to first unread message

Thomas

unread,
May 4, 2012, 10:24:51 AM5/4/12
to Neo4j
Hello,

is it possible in Cypher to get back nodes which have a given number
of children? For example, I want to get all nodes which have exactly
5 children.

I tried it this way:

start n=node(*) match n-[r?]->m where count(m)=5 return n;

But this produces the Exception:

Exception in thread "main" Can't use aggregate functions in the WHERE
clause. Move it to the HAVING clause.

I can't find any information about a "HAVING" clause in the docs?

Thanks for information ;-)

Michael Hunger

unread,
May 4, 2012, 12:00:09 PM5/4/12
to ne...@googlegroups.com
cypher 1.8 has with which can also function as where (query piping)

start n=node(*) match n-->m with n, count(*) as children where children = 2 return n, children

see here: http://tinyurl.com/cqodxah

Andres Taylor

unread,
May 4, 2012, 12:47:13 PM5/4/12
to ne...@googlegroups.com
Ooops. Missed that. HAVING was planned and then scrapped. Michael's suggestion is the correct solution.

Andrés

Thomas

unread,
May 5, 2012, 12:16:37 PM5/5/12
to Neo4j
Thanks for your replies.

I tried the command and get the error:

"start n=node(*) match n-->m with n, count(*) as children where
children = 20, return n, children"
^
at
org.neo4j.cypher.internal.parser.v1_7.CypherParserImpl.parse(CypherParserImpl.scala:
66)


I downloaded the latest stable release and the libs are showing up:

neo4j-cypher-1.7.jar
neo4j-cypher-1.8.M01.jar


So, I need to download the 1.8 snapshot?

And thanks for this wonderful piece of software ;-)




On 4 Mai, 18:47, Andres Taylor <andres.tay...@neotechnology.com>
wrote:
> Ooops. Missed that. HAVING was planned and then scrapped. Michael's
> suggestion is the correct solution.
>
> Andrés
>

Thomas

unread,
May 5, 2012, 12:18:53 PM5/5/12
to Neo4j
Thanks for your replies.
I tried the command and get the error:

"start n=node(*) match n-->m with n, count(*) as children where
children = 20, return n, children"
                             ^
at
org.neo4j.cypher.internal.parser.v1_7.CypherParserImpl.parse(CypherParserImpl.scala:
66)

I downloaded the latest stable release and the libs are showing up:

neo4j-cypher-1.7.jar
neo4j-cypher-1.8.M01.jar

So, I need to download the 1.8 snapshot?
And thanks for this wonderful piece of software ;-)


On 4 Mai, 18:47, Andres Taylor <andres.tay...@neotechnology.com>
wrote:
> Ooops. Missed that. HAVING was planned and then scrapped. Michael's
> suggestion is the correct solution.
>
> Andrés
>
> On Fri, May 4, 2012 at 4:24 PM, Thomas <thomas.zast...@googlemail.com>wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > is it possible in Cypher to get back nodes which have a given number
> > of children?  For example, I want to get all nodes which have exactly
> > 5 children.
>
> > I tried it this way:
>
> > start n=node(*) match n-[r?]->m where count(m)=5 return n;
>
> > But this produces the Exception:
>
> > Exception in thread "main" Can't use aggregate functions in the WHERE
> > clause. Move it to the HAVING clause.
>
> > I can't find any information about a "HAVING" clause in the docs?
>
> > Thanks for information ;-)

On 4 Mai, 18:47, Andres Taylor <andres.tay...@neotechnology.com>
wrote:
> Ooops. Missed that. HAVING was planned and then scrapped. Michael's
> suggestion is the correct solution.
>
> Andrés
>

Peter Neubauer

unread,
May 5, 2012, 12:28:14 PM5/5/12
to ne...@googlegroups.com

Syntax error, remove the comma after the 20?

Andres Taylor

unread,
May 6, 2012, 4:34:14 AM5/6/12
to ne...@googlegroups.com
Something's wrong in your setup. You are using Cypher 1.7, judging by the stack trace you provided. Can you try doing a clean install and copying the database over?

Andrés

Thomas

unread,
May 7, 2012, 9:09:07 AM5/7/12
to ne...@googlegroups.com
Dear all,

Thank you very much. It is an complete new installation of the stable version, I will try the unstable version ;-)

(And yes of course, the comma was a typo ...)
Reply all
Reply to author
Forward
0 new messages