How to make orientDB avoid null

て烟熏妆下的殇ゞ 提交于 2019-12-11 00:47:08

问题


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!


回答1:


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).



回答2:


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)



回答3:


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.



来源:https://stackoverflow.com/questions/33992181/how-to-make-orientdb-avoid-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!