Search code examples
orientdb

How Do I Call SQL Function inside SQL Query


I have 2 OrientDB questions.

  1. For example I have Function called getAll

    "SELECT FROM V WHERE name =:name"

I wish to retrive result in simple SQL Query Something liket his

SELECT type FROM (getAll("Test"))

How I can accomplish this ?

  1. Is it possiable to run new SQL SELECT Query with new parameters based on previous queries? For Example

    SELECT $C FROM V LET $A = (SELECT FROM V WHERE name = 'Test1') , $B = (SELECT FROM V WHERE type = 'Type1') , $C = (SELECT FROM V WHERE type = $B and name = $A)

This case is working but takes a lot of time (as i understands this happens because it runs on all content of V)

Thanks in advance.


Solution

  • To call a function try this:

    SELECT getAll("Test")
    

    with this you retrieve only the RID, if you want all the properties try this:

    SELECT expand(getAll("Test"))
    

    if you want to only retrieve the type property, you can do it in 2 ways:

    1. select type from(SELECT expand(getAll("Test")))
    2. modify you function in this way SELECT type FROM V WHERE name = :name

    For your second question you were pretty close, I've just modify it a little bit:

    SELECT $C FROM V 
    LET $A = (SELECT FROM V WHERE name = 'Test1') , 
    $B = (SELECT FROM V WHERE type = 'Type1') , 
    $C = (SELECT FROM V WHERE type contains $B.type and name contains $A.name)
    

    Hope it helps

    Regards