Skip to content

Commit

Permalink
Optional match does not support where clauses (#1896)
Browse files Browse the repository at this point in the history
* Optional-match-does-not-support-where-clauses-

* Update optional-match.md

* Update optional-match.md
  • Loading branch information
abby-cyber authored Feb 3, 2023
1 parent 4eeceed commit 8066dfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

| Pattern | Example | Description |
| --------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
|Matches patterns against your graph database, just like `MATCH` does. | `MATCH (m)-[]->(n) WHERE id(m)=="player100" OPTIONAL MATCH (n)-[]->(l) WHERE id(n)=="player125" RETURN id(m),id(n),id(l)` | If no matches are found, `OPTIONAL MATCH` will use a null for missing parts of the pattern.|
|Matches patterns against your graph database, just like `MATCH` does. | `MATCH (m)-[]->(n) WHERE id(m)=="player100" OPTIONAL MATCH (n)-[]->(l) RETURN id(m),id(n),id(l)` | If no matches are found, `OPTIONAL MATCH` will use a null for missing parts of the pattern.|

* [LOOKUP](../3.ngql-guide/7.general-query-statements/5.lookup.md)

Expand Down
19 changes: 16 additions & 3 deletions docs-2.0/3.ngql-guide/7.general-query-statements/optional-match.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ The `OPTIONAL MATCH` clause is used to search for the pattern described in it. `

This topic applies to the openCypher syntax in nGQL only.

## Limitations

The `WHERE` clause cannot be used in an `OPTIONAL MATCH` clause.

## Example

The example of the use of `OPTIONAL MATCH` in the `MATCH` statement is as follows:

```ngql
nebula> MATCH (m)-[]->(n) WHERE id(m)=="player100" \
OPTIONAL MATCH (n)-[]->(l) WHERE id(n)=="player125" \
OPTIONAL MATCH (n)-[]->(l) \
RETURN id(m),id(n),id(l);
+-------------+-------------+-------------+
| id(m) | id(n) | id(l) |
+-------------+-------------+-------------+
| "player100" | "team204" | __NULL__ |
| "player100" | "player101" | __NULL__ |
| "player100" | "player101" | "team204" |
| "player100" | "player101" | "team215" |
| "player100" | "player101" | "player100" |
| "player100" | "player101" | "player102" |
| "player100" | "player101" | "player125" |
| "player100" | "player125" | "team204" |
| "player100" | "player125" | "player100" |
+-------------+-------------+-------------+
Expand All @@ -32,11 +40,16 @@ Using multiple `MATCH` instead of `OPTIONAL MATCH` returns rows that match the p

```ngql
nebula> MATCH (m)-[]->(n) WHERE id(m)=="player100" \
MATCH (n)-[]->(l) WHERE id(n)=="player125" \
MATCH (n)-[]->(l) \
RETURN id(m),id(n),id(l);
+-------------+-------------+-------------+
| id(m) | id(n) | id(l) |
+-------------+-------------+-------------+
| "player100" | "player101" | "team204" |
| "player100" | "player101" | "team215" |
| "player100" | "player101" | "player100" |
| "player100" | "player101" | "player102" |
| "player100" | "player101" | "player125" |
| "player100" | "player125" | "team204" |
| "player100" | "player125" | "player100" |
+-------------+-------------+-------------+
Expand Down

0 comments on commit 8066dfb

Please sign in to comment.