Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for new ALL keyword #782

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ label:deprecated[]
RETURN 1 as my\u0085identifier
----
a|
The Unicode character \`\u0085` is deprecated for unescaped identifiers and will be considered as a whitespace character in the future.
The Unicode character \`\u0085` is deprecated for unescaped identifiers and will be considered as a whitespace character in the future.
To continue using it, escape the identifier by adding backticks around the identifier.
This applies to all unescaped identifiers in Cypher, such as label expressions, properties, variable names or parameters.
This applies to all unescaped identifiers in Cypher, such as label expressions, properties, variable names or parameters.
In the given example, the quoted identifier would be \`my�identifier`.

a|
Expand Down Expand Up @@ -65,6 +65,27 @@ The following Unicode Characters are deprecated in identifiers:

|===

=== New features

[cols="2", options="header"]
|===
| Feature
| Details

a|
label:functionality[]
label:new[]

[source, cypher, role=noheader]
----
MATCH (n)
RETURN count(ALL n.prop)
----

| Added a new keyword xref::functions/aggregating.adoc#counting_with_and_without_duplicates[ALL], explicitly defining that the aggregate function is not `DISTINCT`.
This is a mirror of the already existing keyword `DISTINCT` for functions.
|===

[[cypher-deprecations-additions-removals-5.14]]
== Neo4j 5.14

Expand Down
20 changes: 12 additions & 8 deletions modules/ROOT/pages/functions/aggregating.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,17 @@ The number of nodes with the label `Person` and a property `age` is returned:

======


[[counting_with_and_without_duplicates]]
=== Counting with and without duplicates

This example tries to find all friends of friends of `Keanu Reeves` and count them.
The default behavior of the `count` function is to count all matching results, including duplicates.
To avoid counting duplicates, use the `DISTINCT` keyword.

As of Neo4j 5.15, it is also possible to use the `ALL` keyword with aggregating functions.
This will count all results, including duplicates, and is functionally the same as not using the `DISTINCT` keyword.

`count(DISTINCT friendOfFriend)`:: Will only count a `friendOfFriend` once, as `DISTINCT` removes the duplicates.
`count(friendOfFriend)`:: Will consider the same `friendOfFriend` multiple times.
This example tries to find all friends of friends of `Keanu Reeves` and count them.
It shows the behavior of using both the `ALL` and the `DISTINCT` keywords:

.+count()+
======
Expand All @@ -384,18 +388,18 @@ This example tries to find all friends of friends of `Keanu Reeves` and count th
----
MATCH (p:Person)-->(friend:Person)-->(friendOfFriend:Person)
WHERE p.name = 'Keanu Reeves'
RETURN friendOfFriend.name, count(DISTINCT friendOfFriend), count(friendOfFriend)
RETURN friendOfFriend.name, count(friendOfFriend), count(ALL friendOfFriend), count(DISTINCT friendOfFriend)
----

The nodes `Carrie Anne Moss` and `Liam Neeson` both have an outgoing `KNOWS` relationship to `Guy Pearce`.
The `Guy Pearce` node will, therefore, get counted twice when not using `DISTINCT`.

.Result
[role="queryresult",options="header,footer",cols="3*<m"]
[role="queryresult",options="header,footer",cols="4*<m"]
|===

| +friendOfFriend.name+ | +count(DISTINCT friendOfFriend)+ | +count(friendOfFriend)+
| +"Guy Pearce"+ | +1+ | +2+
| friendOfFriend.name | count(friendOfFriend) | count(ALL friendOfFriend) | count(DISTINCT friendOfFriend)
| "Guy Pearce" | 2 | 2 | 1
2+d|Rows: 1

|===
Expand Down