Let is not working on sub-query

60 views
Skip to first unread message

boro...@gmail.com

unread,
Oct 26, 2016, 2:37:19 AM10/26/16
to OrientDB

Hello,

I seem to run into a wall while trying to figure the LET statement which is just failing on me, Here are 2 classes where one has link to another. I need to use the LET statement to get the linked class by provided id, but the result never returns any records. Sub query does return the result correctly, but not the query with the LET statement.

My classes:

create class A extends V
create property A.id INTEGER (NOTNULL TRUE, MANDATORY TRUE)

create class B extends V
create property B.a LINK A (NOTNULL TRUE, MANDATORY TRUE)

insert into A (id) values (1)
insert into B set a = (select from A where id = 1)

select from B let $aa = (select from A where id = 1) where a = $aa
select from B let $aa = (select from A where id = 1) where a = $aa.@rid


Here is the data

orientdb {db=Customers}> select from A

+----+------+------+----+
|#   |@RID  |@CLASS|id  |
+----+------+------+----+
|0   |#185:0|A     |1   |
+----+------+------+----+

1 item(s) found. Query executed in 0.002 sec(s).
orientdb {db=Customers}> insert into B set a = (select from A where id = 1)

Inserted record 'B#189:0{a:#185:0} v1' in 0.004000 sec(s).

orientdb {db=Customers}> select from B

+----+------+------+------+
|#   |@RID  |@CLASS|a     |
+----+------+------+------+
|0   |#189:0|B     |#185:0|
+----+------+------+------+


As you can see from above, class B has a link to class A. In my understanding the query below must work, but it returns nothing. I tried 2 combinations of the query and both don't work.

orientdb {db=Customers}> select from B let $aa = (select from A where id = 1) where a = $aa

0 item(s) found. Query executed in 0.003 sec(s).

orientdb {db=
Customers}> select from B let $aa = (select from A where id = 1) where a = $aa.@rid

0 item(s) found. Query executed in 0.003 sec(s).



Am I doing something wrong or is it a bug?

Oleksandr Gubchenko

unread,
Oct 26, 2016, 2:43:51 AM10/26/16
to orient-...@googlegroups.com
Can you try this one?

select $aa.@rid, a from B
let $aa = (select from A where id = 1)

Upd: sorry, I have misunderstand your question, Luigi's answer will help you.

Luigi Dell'Aquila

unread,
Oct 26, 2016, 2:51:21 AM10/26/16
to orient-...@googlegroups.com
Hi,

The result of a subquery is a result-set, not a single element. I think that rewriting the query this way it should work fine:

select from B let $aa = (select from A where id = 1) where $aa contains a

Thanks

Luigi

2016-10-26 8:43 GMT+02:00 Oleksandr Gubchenko <user.w...@gmail.com>:
Can you try this one?

select $aa.@rid, a from B
let $aa = (select from A where id = 1)

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

boro...@gmail.com

unread,
Oct 26, 2016, 11:45:47 AM10/26/16
to OrientDB
Thanks Luigi, it worked.  I didn't think in terms of a resultset, but it makes sense.


To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.

boro...@gmail.com

unread,
Oct 26, 2016, 11:47:20 AM10/26/16
to OrientDB
Thanks for the response. Your solution also returns the result, but as Luigi mentioned the key is to treat the sub-query as a resultset.
Reply all
Reply to author
Forward
0 new messages