Linkset/Linkmap manipulation


#1

I want to implement suggested ‘time series’ example. So i have created Day:
create class Day
...
create property Day.log LINKSET Log (DEFAULT [])

And some Log class. I have created Day 85:0 and Log 49:0 entities.
When i try to extend my linkset using SQL:
update #85:0 add log = #49:0
from console, it says:
Error: com.orientechnologies.orient.core.exception.OCommandExecutionException: Cannot execute with UPDATE PUT/ADD/INCREMENT new executor: ADD log = #49:0
Ok, i use it in java, so
Set<? extends ORecord> logset = dayElement.getProperty("log");
logset.add(myLog.getRecord());
dayElement.save();

It works. So i have questions:

  1. Which is right way to add element to set or map using SQL syntax? There is no documented commands for 3.x versions.
  2. Will dayElement.getProperty(“log”) load entire set of @rid’s or can be safely used for large number of records?

#2

Hi @pcholder

In v 3.0 we added a new || operator for list manipulation, that is much more flexible than the old UPDATE ADD

You can write your query as follows:

update #85:0 SET log = log || #49:0

or

update #85:0 SET log =  #49:0 || log

depending if you need the new element as head or tail

Full docs here: https://orientdb.com/docs/3.0.x/sql/SQL-Syntax.html#array-concatenation

Thanks

Luigi