- Neo4j Tutorial
- Neo4j - Home
- Neo4j - Overview
- Neo4j - Data Model
- Neo4j - Environment Setup
- Neo4j - Building Blocks
- Neo4j CQL Write Clauses
- Neo4j - Merge Command
- Neo4j - Set Clause
- Neo4j - Delete Clause
- Neo4j - Remove Clause
- Neo4j - Foreach Clause
- Neo4j CQL Read Clause
- Neo4j - Match Clause
- Neo4j - Optional Match Clause
- Neo4j - Where Clause
- Neo4j - Count Function
- Neo4j CQL General Clauses
- Neo4j - Return Clause
- Neo4j - Order By Clause
- Neo4j - Limit Clause
- Neo4j - Skip Clause
- Neo4j - With Clause
- Neo4j - Unwind Clause
- Neo4j CQL Functions
- Neo4j - String Functions
- Neo4j - Aggregation Function
- Neo4j CQL Admin
- Neo4j - Backup & Restore
- Neo4j - Index
- Neo4j - Create Unique Constraint
- Neo4j - Drop Unique
- Neo4j Useful Resources
- Neo4j - Quick Guide
- Neo4j - Useful Resources
- Neo4j - Discussion
Neo4j CQL - Relationship Functions
Neo4j CQL has provided a set of Relationship functions to know the details of a Relationship in getting Start Node,End Node etc. details.
Here, we are going to discuss some of the important and frequently used functions
Relationship Functions List
S.No. | Function | Description |
---|---|---|
1. | STARTNODE | It is used to know the Start Node of a Relationship. |
2. | ENDNODE | It is used to know the End Node of a Relationship. |
3. | ID | It is used to know the ID of a Relationship. |
4. | TYPE | It is used to know the TYPE of a Relationship in string representation. |
Now we will discuss each Neo4j CQL Relationship Functions in detail with examples
STARTNODE
It takes a string as an input and convert into upper case letters. All CQL Functions should use "( )" brackets.
Function syntax
STARTNODE (<relationship-label-name>)
NOTE:-
<relationship-label-name> may be a property name of a node or relationship from Neo4j Database.
Example -
This example demonstrates how to use CQL STARTNODE Relationship function to retrieve a Start Node Details of a Relationship.
Before executing STARTNODE() function on Relationship "ACTION_MOVIES", we will check it's details
Step 1 - Type the below command at dollar prompt in Data Browser.
MATCH (video1:YoutubeVideo1)-[movie:ACTION_MOVIES]->(video2:YoutubeVideo2) RETURN movie
Step 2 - Click on Execute button and observe the results.
Here, We can observe that STARTNODE of Relationship "ACTION_MOVIES" is "YoutubeVideo1". Let us check this with function.
Step 3 - Type the below command and click on Execute button.
MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN STARTNODE(movie)
It uses STARTNODE() Relationship function to print Start Node of Relationship "ACTION_MOVIES".
Here, We can observe that STARTNODE of Relationship "ACTION_MOVIES" is "YoutubeVideo1".
Example -
This example demonstrates how to use CQL ENDNODE Relationship function to retrieve a End Node Details of a Relationship.
Before executing ENDNODE() function on Relationship "ACTION_MOVIES", we will check it's details
Step 1 - Type the below command at dollar prompt in Data Browser.
MATCH (video1:YoutubeVideo1)-[movie:ACTION_MOVIES]->(video2:YoutubeVideo2) RETURN movie
Step 2 - Click on Execute button and observe the results.
Here, We can observe that End Node of Relationship "ACTION_MOVIES" is "YoutubeVideo2". Let us check this with function.
Step 3 - Type the below command and click on Execute button.
MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN ENDNODE(movie)
It uses ENDNODE() Relationship function to print Start Node of Relationship "ACTION_MOVIES".
Here, We can observe that ENDNODE of Relationship "ACTION_MOVIES" is "YoutubeVideo2".
Example -
This example demonstrates how to use CQL ID & TYPE Relationship functions to retrieve Id and Type Details of a Relationship.
Before executing ID & TYPE functions on Relationship "ACTION_MOVIES", we will check it's details
Step 1 - Type the below command at dollar prompt in Data Browser.
MATCH (video1:YoutubeVideo1)-[movie:ACTION_MOVIES]->(video2:YoutubeVideo2) RETURN movie
Step 2 - Click on Execute button and observe the results.
Here, We can observe that ID and TYPE of Relationship "ACTION_MOVIES" are "2" and "ACTION_MOVIES". Let us check this with function.
Step 3 - Type the below command and click on Execute button.
MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN ID(movie),TYPE(movie)
It uses ID() and TYPE() Relationship functions to print ID and Type of Relationship "ACTION_MOVIES" details.
Here, We can observe that ID and TYPE of Relationship "ACTION_MOVIES" are "2" and "ACTION_MOVIES".