Overview
The graph pattern YIELD
clause can be used at the end of a MATCH
statement to select columns of the binding table to allow exposure in subsequent parts of the query.
<match statement> ::=
[ "OPTIONAL" ] "MATCH" <graph pattern> [ <graph pattern yield clause> ]
<graph pattern yield clause> ::=
"YIELD" <graph pattern yield item> [ { "," <graph pattern yield item> }... ]
<graph pattern yield item> ::= <element variable> | <path variable>
Example Graph
The following examples run against this graph:
To create this graph, run the following query against an empty graph:
INSERT (rowlock:User {_id: 'U01', name: 'rowlock'}),
(brainy:User {_id: 'U02', name: 'Brainy'}),
(purplechalk:User {_id: 'U03', name: 'purplechalk'}),
(mochaeach:User {_id: 'U04', name: 'mochaeach'}),
(lionbower:User {_id: 'U05', name: 'lionbower'}),
(c01:Club {_id: 'C01', since: 2005}),
(c02:Club {_id: 'C02', since: 2005}),
(rowlock)-[:Follows {createdOn: '2024-1-5'}]->(brainy),
(mochaeach)-[:Follows {createdOn: '2024-2-10'}]->(brainy),
(brainy)-[:Follows {createdOn: '2024-2-1'}]->(purplechalk),
(purplechalk)-[:Follows {createdOn: '2024-5-3'}]->(lionbower),
(brainy)-[:Joins {memberNo: 1}]->(c01),
(lionbower)-[:Joins {memberNo: 2}]->(c01),
(mochaeach)-[:Joins {memberNo: 9}]->(c02)
MATCH YIELD
This query returns only n1
, as it is the only variable specified in the YIELD
clause:
MATCH (n1:User), (n2:Club)
YIELD n1
RETURN *
Result: n1
_id | _uuid | schema | values |
---|---|---|---|
U05 | Sys-gen | User | {name: "lionbower"} |
U05 | Sys-gen | User | {name: "lionbower"} |
U04 | Sys-gen | User | {name: "mochaeach"} |
U04 | Sys-gen | User | {name: "mochaeach"} |
U03 | Sys-gen | User | {name: "purplechalk"} |
U03 | Sys-gen | User | {name: "purplechalk"} |
U02 | Sys-gen | User | {name: "Brainy"} |
U02 | Sys-gen | User | {name: "Brainy"} |
U01 | Sys-gen | User | {name: "rowlock"} |
U01 | Sys-gen | User | {name: "rowlock"} |
This query throws syntax error since n2
is not selected in the YIELD
clause, thus it cannot be accessed by the RETURN
statement:
MATCH (n1:User), (n2:Club)
YIELD n1
RETURN n1, n2
Result: n2
not found
This query returns n1
and e
:
MATCH (n1:Club)
MATCH (n2:Club)<-[e:Joins WHERE e.memberNo < 3]-()
YIELD e
RETURN *
Result:
n1
_id | _uuid | schema | values |
---|---|---|---|
C01 | Sys-gen | Club | {since: 2005} |
C01 | Sys-gen | Club | {since: 2005} |
C02 | Sys-gen | Club | {since: 2005} |
C02 | Sys-gen | Club | {since: 2005} |
e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | {memberNo: 1} |
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | {memberNo: 1} |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | {memberNo: 2} |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | {memberNo: 2} |