简体   繁体   中英

orientdb sql update edge?

I have been messing around with orientdb sql, and I was wondering if there is a way to update an edge of a vertex, together with some data on it.

assuming I have the following data: Vertex: Person, Room Edge: Inside (from Person to Room)

something like:

UPDATE Persons SET phone=000000, out_Inside=(
    select @rid from Rooms where room_id=5) where person_id=8

obviously, the above does not work. It throws exception:

Error: java.lang.ClassCastException: com.orientechnologies.orient.core.id.ORecordId cannot be cast to com.orientechnologies.orient.core.db.record.ridbag.ORidBag

I tried to look at the sources at github searching for a syntax for bag with 1 item, but couldn't find any (found %, but that seems to be for serialization no for SQL).

(1) Is there any way to do that then? how do I update a connection? Is there even a way, or am I forced to create a new edge, and delete the old one?

(2) When writing this, it came to my mind that perhaps edges are not the way to go in this case. Perhaps I should use a LINK instead. I have to say i'm not sure when to use which, or what are the implications involved in using any of them. I did found this though:

https://groups.google.com/forum/#!topic/orient-database/xXlNNXHI1UE

comment 3 from the top, of Lvc@, where he says:

"The suggested way is to always create an edge for relationships"

Also, even if I should use a link, please respond to (1). I would be happy to know the answer anyway.

ps In my scenario, a person can only be at one room. This will most likely not change in the future. Obviously, the edge has the advantage that in case I might want to change it (however improbable that may be), it will be very easy.

Solution (partial)

(1) The solution was simply to remove the field selection. Thanks for Lvca for pointing it out!

(2) --Still not sure--

CREATE EDGE and DELETE EDGE commands have this goal: avoid the user to fight with underlying structure.

However if you want to do it (a little "dirty"), try this one:

UPDATE Persons SET phone=000000, out_Inside=(
  select from Rooms where room_id=5) where person_id=8
update EDGE Custom_Family_Of_Custom 
set survey_status = '%s', 
apply_source = '%s' 
where @rid in (
select level1_e.@rid from (
MATCH {class: Custom, as: custom, where: (custom_uuid = '%s')}.bothE('Custom_Family_Of_Custom') {as: level1_e} .bothV('Custom') {as: level1_v, where: (custom_uuid = '%s')} return level1_e
)
)

it works well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM