OrientDB – Functions


OrientDB – Functions


”;


This chapter explains the complete reference of different types of functions in OrientDB. The following table defines the list of functions, which are categorized by their functionality.

Graph Functions

Try some graph functions along with the following queries.

Execute the following query to get all the outgoing vertices from all the vehicle vertices.

orientdb {db = demo}>SELECT out() from Vehicle

If the above query is executed successfully, you will get the following output.

---+----------+--------- 
 # | @class   | out 
---+----------+--------- 
 0 | Vehicle  | #11:2 
 1 | Vehicle  | #13:1 
 2 | Vehicle  | #13:4 
---+----------+--------- 

Execute the following query to get both incoming and outgoing vertices from the vertex #11:3.

orientdb {db = demo}>SELECT both() FROM #11:3 

If the above query is executed successfully, you will get the following output.

---+----------+--------+------- 
 # | @class   | out    | in  
---+----------+--------+------- 
 0 | Vehicle  | #13:2  | #10:2   
 ---+----------+-------+-------

Math Functions

Try some math functions using the following queries.

Execute the following query to get the sum of salaries of all employees.

orientdb {db = demo}>SELECT SUM(salary) FROM Employee 

If the above query is executed successfully, you will get the following output.

---+----------+--------- 
 # | @CLASS   | sum 
---+----------+--------- 
 0 | null     | 150000 
---+----------+---------

Execute the following query to get the average salary of all employees.

orientdb {db = demo}>SELECT avg(salary) FROM Employee

If the above query is executed successfully, you will get the following output.

---+----------+--------- 
 # | @CLASS   | avg 
---+----------+--------- 
 0 | null     | 25 
---+----------+--------- 

Collections Functions

Try some collection functions using the following queries.

Execute the following query to get a set of teachers, teaching class 9th.

orientdb {db = demo}>SELECT ID, set(teacher.id) AS teacherID from classess where class_id = 9 

If the above query is executed successfully, you will get the following output.

---+----------+--------+-------------------------- 
 # | @CLASS   | id     | TeacherID 
---+----------+--------+-------------------------- 
 0 | null     | 9     |   1201, 1202, 1205, 1208 
---+----------+-------+---------------------------

Misc Functions

Try some Misc functions using the following queries.

Execute the following query to learn how to execute if expression.

orientdb {db = demo}> SELECT if(eval("name = ''satish''"), "My name is satish", 
"My name is not satish") FROM Employee

If the above query is executed successfully, you will get the following output.

----+--------+----------------------- 
#   |@CLASS  | IF 
----+--------+----------------------- 
0   |null    |My name is satish  
1   |null    |My name is not satish 
2   |null    |My name is not satish  
3   |null    |My name is not satish  
4   |null    |My name is not satish  
----+--------+------------------------ 

Execute the following query to get system date.

orientdb {db = demo}> SELECT SYSDATE() FROM Employee

If the above query is executed successfully, you will get the following output.

----+--------+----------------------- 
#   |@CLASS  | SYSDATE 
----+--------+----------------------- 
0   |null    |2016-02-10 12:05:06 
1   |null    |2016-02-10 12:05:06 
2   |null    |2016-02-10 12:05:06 
3   |null    |2016-02-10 12:05:06 
4   |null    |2016-02-10 12:05:06 
----+--------+------------------------ 

By using this function thoroughly you can easily manipulate the OrientDB data.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *