This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results forΒ

- Neo4j
- Technical Discussions
- Neo4j Graph Platform
- Re: A small question about cypher semantics

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β10-06-2022 04:21 AM - edited β10-06-2022 04:24 AM

How should I understand the semantics of these cypher statements. Why the first and second statements have no results and the third statement outputs a line of results?

neo4j@neo4j> with 3 as c1 match (v:nonexist) return count(v) as c2, c1;

+---------+

| c2 | c1 |

+---------+

+---------+

0 rows available after 65 ms, consumed after another 17 ms

neo4j@neo4j> with 3 as c1 match (v:nonexist) return c1;

+----+

| c1 |

+----+

+----+

0 rows available after 41 ms, consumed after another 0 ms

neo4j@neo4j> with 3 as c1 match (v:nonexist) return count(v) as c2;

+----+

| c2 |

+----+

| 0 |

+----+

neo4j@neo4j> match (v:nonexist) return count(v) as c2;

+----+

| c2 |

+----+

| 0 |

+----+

Solved! Go to Solution.

1 ACCEPTED SOLUTION

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β10-06-2022 04:48 AM

A neo4j query produces rows of data for a single match. The way 'with' works is its variable is added to each row of the 'match' result. For example, 'with 3 as c1 match(n) return *', would result in rows as follows (assuming there is a match):

c1, n

3, first instance of n

3, second instance of n

etc.

Based on above, this is how I view each of your questions.

1. when 'with c1 match(v:nonexist)' produces a null result, you get a empty result since you are returning something from the result set (c1).

2. Same reason as #1

3 & 4. These differ from #1 and #2, since you are not requesting something returned from the row data, only the aggregate count of the rows is returned, which is zero for the null rows result.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β10-06-2022 04:48 AM

A neo4j query produces rows of data for a single match. The way 'with' works is its variable is added to each row of the 'match' result. For example, 'with 3 as c1 match(n) return *', would result in rows as follows (assuming there is a match):

c1, n

3, first instance of n

3, second instance of n

etc.

Based on above, this is how I view each of your questions.

1. when 'with c1 match(v:nonexist)' produces a null result, you get a empty result since you are returning something from the result set (c1).

2. Same reason as #1

3 & 4. These differ from #1 and #2, since you are not requesting something returned from the row data, only the aggregate count of the rows is returned, which is zero for the null rows result.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β10-06-2022 05:24 AM

@glilienfield Very clear answer! thanks a lot for the reply.

Nodes 2022

All the sessions of the conference are now available online

Related Content

- Which query is more expensive? in Neo4j Graph Platform
- How to create relation only for new add data and don't travel entire graph that already in neo4j in Neo4j Graph Platform
- Some questions about path pattern matching in Neo4j Graph Platform
- Cypher Question: Checking for Known Path Based on Node Properties & Returning Leaf Node in Neo4j Graph Platform
- Getting "The transaction has been closed." error while projecting a subgraph with GDS in Neo4j Graph Platform