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

document the remove clause #101

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
68 changes: 68 additions & 0 deletions cypher/remove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: "REMOVE"
nav_order: 22
description: >
REMOVE is used to remove attributes from node and relationships, in addition to
removing labels from nodes.
parent: "Cypher Language"
---

# REMOVE

## Example graph

```cypher
CREATE
(billy :Player {name: 'Billy', score: 84}),
(andy :Player {name: 'Andy', score: 21}),
(lori :Player:Admin {name: 'Lori', score: 90})
```

## Remove attributes

The following query removes the 'score' attribute from the node
representing Andy.

```cypher
MATCH (n {name: 'Andy'})
REMOVE n.score
RETURN n.name, n.score
```

Result:
|n.name|n.score|
|------|-------|
|"Andy"| Null |

Comment on lines +21 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing examples and fix table formatting.

The section should include:

  1. Example of removing relationship properties
  2. Example of removing multiple properties at once
  3. Proper table formatting with surrounding blank lines
 ## Remove attributes

+### Remove node properties
+
 The following query removes the 'score' attribute from the node
 representing Andy.

 ```cypher
 MATCH (n {name: 'Andy'})
 REMOVE n.score
 RETURN n.name, n.score

Result:
+

n.name n.score
"Andy" Null

+### Remove relationship properties
+
+The following query removes the 'since' property from KNOWS relationships:
+
+cypher +MATCH (lori {name: 'Lori'})-[r:KNOWS]->(bob) +REMOVE r.since +RETURN type(r), r.since +
+
+Result:
+
+|type(r)|r.since|
+|-------|-------|
+|"KNOWS"| Null |
+
+### Remove multiple properties
+
+You can remove multiple properties in a single REMOVE clause:
+
+cypher +MATCH (n {name: 'Billy'}) +REMOVE n.score, n.name +RETURN n +


<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

33-33: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit -->


## Remove a label from a node

To remove a label from a node use the REMOVE clause as follows:

```cypher
MATCH (n {name: 'Lori'})
REMOVE n:Admin
RETURN n.name, labels(n)
```

Result:
|n.name|abels(n)|
|------|--------|
|"Lori"|[Player]|

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo and add important notes about label removal.

  1. There's a typo in the table header ("abels" should be "labels")
  2. Add a note about attempting to remove non-existent labels
  3. Fix table formatting
 ## Remove a label from a node

 To remove a label from a node use the REMOVE clause as follows:
+
+Note: Attempting to remove a non-existent label from a node is a no-op operation
+and will not cause an error.

 ```cypher
 MATCH (n {name: 'Lori'})
 REMOVE n:Admin
 RETURN n.name, labels(n)

Result:
+
-|n.name|abels(n)|
+|n.name|labels(n)|
|------|--------|
|"Lori"|[Player]|
+


<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~49-~49: A punctuation mark might be missing here.
Context: ...labels(n) ```  Result: |n.name|abels(n)| |------|--------| |"Lori"|[Player]|   ##...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

</details>
<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

49-49: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit -->


## Removing multiple labels from a node

Similar to removing a single label from a node we can use the REMOVE clause
to remove multiple labels in one go

```cypher
MATCH (n :Player {name: 'Lori'})
REMOVE n:Admin:Player
RETURN n.name, labels(n)
```

Result:
|n.name|abels(n)|
|------|--------|
|"Lori"|[] |
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo and add clarification about multiple label removal.

  1. Fix the typo in table header ("abels" should be "labels")
  2. Add a note about label order independence
  3. Fix table formatting
 ## Removing multiple labels from a node

 Similar to removing a single label from a node we can use the REMOVE clause
-to remove multiple labels in one go
+to remove multiple labels in one go. The order of labels in the REMOVE clause
+does not matter.

 ```cypher
 MATCH (n :Player {name: 'Lori'})
 REMOVE n:Admin:Player
 RETURN n.name, labels(n)

Result:
+
-|n.name|abels(n)|
+|n.name|labels(n)|
|------|--------|
|"Lori"|[] |
+


<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~66-~66: A punctuation mark might be missing here.
Context: ...labels(n) ```  Result: |n.name|abels(n)| |------|--------| |"Lori"|[]      | 

(AI_EN_LECTOR_MISSING_PUNCTUATION)

</details>
<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

66-66: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit -->

Loading