OrientDB: How to update column using select query

我是研究僧i 提交于 2019-12-01 21:33:51

I tried searching but did not get any clean ans, but i making following change worked for me & got the job done :)

update Table1 set name=(select productname from Table2 where
@rid=$parent.$current.productid), 
name= name.replace("\[","").replace("\]","")

Hope this saves time for someone.

You observe this behavior since the sub query (the select query) always returns a collection. The LET block would help you here. Following is how you use the LET block in your query;

update Table1 set name = $name[0].productname LET $name = (select productname from Table2 where @rid=$parent.$current.productId)

The LET block is useful for sub queries, projections and holding results that will be used multiple times.

You can find more information here.

Hope this helps.

Apparently your answer (@Omega Silva) does not work as it is.

This is the error I get

I have the same problem here and I haven't found an elegant solution.

I want to copy the @rid of Table2 into a field "r1" of Table1 where Table2.f1=Table1.f2 (f1 & f2 just two other fields).

The only solution I came up with is this:

UPDATE Table1 SET r1=(SELECT @rid FROM Table2 
WHERE Table2.f1=$parent.$current.f2)

And this returns a string with the entire field/value list. Then I trim it as follows:

UPDATE Table1 SET r1=r1.substring(6,12) 

(to keep just the @rid part)

But it seems to me that there has to be a better/more elegant solution, with a single query.

Any ideas?

update Table1 set name=(select productname from Table2 where
@rid=$parent.$current.productid), 
name= name.replace("[","").replace("]","")

Try that method (hierahical linking)

UPDATE test1 SET ttt=(SELECT FROM test1 WHERE id=$parent.$current.parentId),
parent=ttt[0].@rid,ttt=null

It is works on orientdb 2.19

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