Search code examples
orientdb

When to use expand() and/or sub-selects


I would be grateful if someone could explain to me the difference between the following three queries and why only the last one works.

select out() from #1:0 where @class instanceof 'BaseClass'
select expand(out()) from #1:0 where @class instanceof 'BaseClass'
select from (select expand(out()) from #1:0) where @class instanceof 'BaseClass'

Thanks a lot for your help!


Solution

  • Because the where condition is not well applied in the first 2 cases. The first one out() returns only a collection of record id, With the second one the array is expanded and transformed in a collection of document, but i think the where condition is applied before the expand so like case 1 does not work.

    If you prefer to not use subquery you can always do

    select expand(out()[ @class = 'BaseClass']) from #1:0