Reputation: 33
When I execute code below,
select expand(distinct(@rid)) from (
select from V
where @rid = 'number not exist'
)
it returns
OCommandExecutionException:
expression item '@rid' cannot be resolved because current record is NULL
This inside select is just for test and it returns no record.
I want null
to be returned if select returns no record
and expand(distinct(@rid))
if select returns some @rid
.
The environment is OrientDB 2.1.5 and it occurs both in console and studio.
Thanks!
Upvotes: 2
Views: 349
Reputation: 1263
You can do:
SELECT expand(ifnull(@rid, 'null'))
FROM V WHERE @rid = 'number not exist'
It will expand the record if exists, otherwise return empty.
Upvotes: 0
Reputation: 116690
Your query works correctly in version 2.1.7:
OrientDB console v.2.1.7-SNAPSHOT (build 4) www.orientdb.com
...
orientdb> connect ...
orientdb {db=demo}> select expand(distinct(@rid)) from (select from V where @rid = 'number not exist')
0 item(s) found. Query executed in 0.076 sec(s).
Upvotes: 1
Reputation: 3570
You can create a simple javascript function as the following
var g=orient.getGraph();
var b=g.command("sql","select from V where @rid = #12:0");
if(b.length>0){
var c=g.command("sql","select expand(distinct(@rid)) from ( select from V where @rid = #12:0)");
return c;
}
else
return null;
and call it from console or studio
select expand(result) from (select yourFunction() as result)
Upvotes: 0