Search code examples
orientdb

OrientDB SELECT and subqueries


I'm really puzzled about this. Why does this works:

SELECT out('Posted').out('IsFromCategory') FROM #18:1

And this does not:

SELECT out('IsFromCategory') FROM (SELECT out('Posted') FROM #18:1)

That's not me real logic, but is something I came up doing some tests...


Solution

  • As you realised, you need to use expand in your subquery, so it would look like

    SELECT out('IsFromCategory') FROM (SELECT expand(out('Posted')) FROM #18:1)
    

    It's like the subquery without the expand returns a list of @rid, so there's nothing to select from there, while after expanding, you get a list with the whole entities (vertices) from which you can traverse any edge they have.

    (Not sure why this behaves differently from your first query. Maybe, because the first is one query and you ask explicitly to traverse, whereas the second is two queries and when the subquery returns it doesn't know that you want the whole vertex retrieved).