How to send parameters in sql function?

Hi @luigidellaquila

I have a sql query
MATCH {class: PT, as: pt, where: (TrxID in [‘T7’,‘T11’,‘T8’])}-HasAccount->{class: Account, as: ac}-HasCustNo->{class:CustNo, as:cn}
RETURN $pathelements

I need to save this as a function and pass ‘T7’,‘T11’,‘T8’ these 3 ids

I tried like this, but not working

Can I have some help

Also may I know how to call the function

Thanks

Hi @hanzgs

you have to use named params notation, ie.

MATCH {class: PT, as: pt, where: (TrxID in [:id1, :id2, :id3])}-HasAccount->{class: Account, as: ac}-HasCustNo->{class:CustNo, as:cn}
RETURN $pathelements

There are many ways to invoke a function.
In a SQL BATCH script you can just invoke it as it is, eg.

T7Ring("T7", "T11", "T8")

In a normal SQL query you can use it in projections or in the filters, eg.

SELECT T7Ring("T7", "T11", "T8") as foo

you can also invoke it from the REST interface, see https://orientdb.com/docs/3.0.x/misc/OrientDB-REST.html#function

I hope it helps

Thanks

Luigi

1 Like

Thank You Very Much, Its working good.

May I know how to do in gremlin queries please

Error is
{
“errors”: [
{
“reason”: “Bad request”,
“code”: 400,
“content”: "Error on evaluation of the script library. Error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:\r\nScript8.groovy: 6: unexpected token: : @ line 6, column 29.\r\n g.V(g.V().has(‘PT’, ‘TrxID’,:id).next()).both().both().both().cyclicPath().path()\r\n ^\r\n\r\n1 error\r\n\nScript library was:\ndef AccLabels() {\ng.V().hasLabel(‘Account’) \n}\n\ndef CyclePaths(id) {\ng.V(g.V().has(‘PT’, ‘TrxID’,:id).next()).both().both().both().cyclicPath().path()\n}\n\ndef Labels() {\ng.V().label()\n}\n\ndef Betweeness_on_Trans() {\ng.V(g.V().has(‘PT’,‘TrxID’,‘T7’).next()).repeat(.bothE().subgraph(‘subGraph’).bothV()).times(3).cap(‘subGraph’).next().traversal().V().as(“v”).repeat(both().simplePath().as(“v”)).emit().filter(project(“x”,“y”,“z”).by(select(first, “v”)).by(select(last, “v”)).by(select(all, “v”).count(local)).as(“triple”).coalesce(select(“x”, “y”).as(“a”).select(“triples”).unfold().as(“t”).select(“x”,“y”).where(eq(“a”)).select(“t”),store(“triples”)).select(“z”).as(“length”).select(“triple”).select(“z”).where(eq(“length”))).select(all, “v”).unfold().groupCount().next()\n}\n\ndef Closeness_on_Trans() {\ng.V(g.V().has(‘PT’,‘TrxID’,‘T7’).next()).repeat(.bothE().subgraph(‘subGraph’).bothV()).times(3).cap(‘subGraph’).next().traversal().withSack(1f).V().as(“v”).repeat(both().simplePath().as(“v”)).emit().filter(project(“x”,“y”, “z”).by(select(first, “v”)).by(select(last, “v”)).by(select(all, “v”).count(local)).as(“triple”).coalesce(select(“x”, “y”).as(“a”).select(“triples”).unfold().as(“t”).select(“x”,“y”).where(eq(“a”)).select(“t”),store(“triples”)).select(“z”).as(“length”).select(“triple”).select(“z”).where(eq(“length”))).group().by(select(first,“v”)).by(select(all, “v”).count(local).sack(div).sack().sum()).next()\n}\n\n\r\n\tDB name=“Test1"”
}
]
}

Is this because in gremlin console we initiate the graph as
graph = OrientGraph.open(“plocal:C:/OrientdbGremlin3.0.25/databases/Test1”);
g = graph.traversal()
g.V()

but here calling g.V() straight

The 2nd question is
in gremlin console we can initialise a variable like
trx1 = g.V().has(‘PT’, ‘TrxID’,‘T7’).next()
g.V(trx1).both().both().simplePath().path()

may I know (trx1) how to do that in server browse?

Thanks