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.FunctionDescription
1.STARTNODEIt is used to know the Start Node of a Relationship.
2.ENDNODEIt is used to know the End Node of a Relationship.
3.IDIt is used to know the ID of a Relationship.
4.TYPEIt 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
Neo4j CQL Tutorial

Step 2 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

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)
Neo4j CQL Tutorial

It uses STARTNODE() Relationship function to print Start Node of Relationship "ACTION_MOVIES".

Neo4j CQL Tutorial

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
Neo4j CQL Tutorial

Step 2 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

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)
Neo4j CQL Tutorial

It uses ENDNODE() Relationship function to print Start Node of Relationship "ACTION_MOVIES".

Neo4j CQL Tutorial

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
Neo4j CQL Tutorial

Step 2 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

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)
Neo4j CQL Tutorial

It uses ID() and TYPE() Relationship functions to print ID and Type of Relationship "ACTION_MOVIES" details.

Neo4j CQL Tutorial

Here, We can observe that ID and TYPE of Relationship "ACTION_MOVIES" are "2" and "ACTION_MOVIES".

Advertisements