Skip to content

Conversation

@JPryce-Aklundh
Copy link
Collaborator

No description provided.

Copy link
Contributor

@hvub hvub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things pointed out, but overall this is very nice. Thank you.


| GQ09
| `LET` statement
| xref:clauses/let.adoc[`LET`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI: There is a caveat to this, since there is a sub-functionality which we do not support, cf. Appendix of the CIP. However, that is much in the detail and other implementation do not support that either. Additionally, I am trying to make this bit optional in the standard. Bottom line: I would not change anything here at this point, but we may want to in the future (e.g. when making it optional in the standard fails).

m| xref::clauses/unwind.adoc[UNWIND ... [AS]]
| Expands a list into a sequence of rows.
m| xref::clauses/let.adoc[LET]
| Assigns expressions to variables.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More correct is that the results of expressions are assigned to that variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could say something like "defines additional variables" or "binds additional variables". Not sure I like these more. Just throwing out ideas.

Comment on lines 42 to 44
m| xref::clauses/filter.adoc[FILTER]
| Adds filters to queries.
label:new[Introduced in Neo4j 2025.03]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't saw this on the FILTER review, but I think this FILTER is in the wrong section, since it does not project anything. Reading clauses is probably better.


`LET` binds expressions to variables.
For queries involving several chained expressions, it can be a more succinct and readable alternative to xref:clauses/with.adoc[`WITH`].
Unlike `WITH`, `LET` cannot limit the scope of variables available to subsequent clauses.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unlike `WITH`, `LET` cannot limit the scope of variables available to subsequent clauses.
Unlike `WITH`, `LET` does not remove variables from the scope for subsequent clauses.

I feel this sound more positive ... "it does not limit" is somehow slightly negatively connotated for me, while "it does not remove" is somehow slightly negatively connotated for me. ... may that is just me.

[[assigning-expressions-to-variables]]
== Assigning expressions to a variable

Both `Let` and `WITH` can be used to assign variables to an expression:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Both `Let` and `WITH` can be used to assign variables to an expression:
Both `LET` and `WITH` can be used to assign variables to an expression:

Comment on lines 66 to 67
* `LET` syntax: `LET <variable> = <expression>, <variable> = <expression>`
* `WITH` syntax: `WITH <expression> AS <variable>, <expression> AS <variable>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may make look like they do the same, which they do not. As explained at the top and in the next section ("Variables in scope: comparing LET and WITH"). So, I wonder if we need that here.

May we make this section just about LET and do not mention WITH at all. It is mentioned enough at the top and in the next section.

----

[[assigning-expressions-to-variables]]
== Assigning expressions to a variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cf. Comment on the index page. (Also the plural doesn't fit, because it is one expression per variable. That one expression may be evaluated to multiple values.)

Here is another proposal:

Suggested change
== Assigning expressions to a variable
== Assigning values to a variable

=== Variables in scope

`LET` and `WITH` behave differently in terms of what variables remain in scope for subsequent clauses.
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses.
Unlike `WITH`, `LET` does not drop variables from the scope of subsequent clauses.

cf. above. I like this version with "drop" over my own suggestion from above.

Or more LET-oriented:

Suggested change
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses.
`LET` does not drop variables from the scope of subsequent clauses, while `WITH` does.

(or the other way around).

We should pay attention that the page works for someone who is not familiar with WITH.

[[chaining-expressions]]
=== Chaining expressions

The fact that `LET` does not drop variables means that it can be used to chain expressions in a clear and concise manner, where variables bound in one `LET` clause can be referenced by subsequent clauses.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

----
MATCH (c:Customer)-[:BUYS]->(p:Product)
WITH DISTINCT c, sum(p.price) AS totalSpent
LET fullName = c.firstName + ' ' + c.lastName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LET fullName = c.firstName + ' ' + c.lastName,
LET fullName = c.firstName + ' ' + c.lastName

@neo-technology-commit-status-publisher
Copy link
Collaborator

neo-technology-commit-status-publisher commented Mar 10, 2025

Thanks for the documentation updates.

The preview documentation has now been torn down - reopening this PR will republish it.

@JPryce-Aklundh JPryce-Aklundh merged commit a148653 into neo4j:cypher-25 Mar 10, 2025
4 checks passed
@JPryce-Aklundh JPryce-Aklundh deleted the let_playground branch March 10, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants