Update one or more records in the current database. Remember that OrientDB can work also in schema-less mode, so you can create any field on-the-fly. Furthermore, OrientDB works on collections. This is the reason why OrientDB SQL has some extensions to handle collections.
UPDATE <class>|cluster:<cluster>|<recordID>
[SET|INCREMENT|ADD|REMOVE|PUT <field-name> = <field-value>[,]*]|[CONTENT|MERGE <JSON>]
[UPSERT]
[RETURN <returning> [<returning-expression>]]
[WHERE <conditions>]
[LOCK default|record]
[LIMIT <max-records>] [TIMEOUT <timeout>]
Where:
<returning>
. If <returning-expression>
is specified (optional) and returning is BEFORE or AFTER, then the expression value is returned instead of record. <returning>
can be a value between:Note that RecordID must be prefixed with '#'. Example: #12:3.
To know more about conditions, take a look at WHERE conditions.
UPSERT guarantee the atomicity only if a UNIQUE index is created and the lookup on index is done by where condition.
In this example a unique index on Client.id must be present to guarantee uniqueness on concurrent operations:
update client set id = 23 upsert where id = 23
> UPDATE Profile SET nick='Luca' WHERE nick IS NULL
Updated 2 record(s) in 0,008000 sec(s).
> UPDATE Profile REMOVE nick
> UPDATE Account ADD addresses=#12:0
> UPDATE Account REMOVE addresses=#12:0
> UPDATE Account PUT addresses='Luca', #12:0
> UPDATE Account REMOVE addresses='Luca'
Update command can take a JSON as value to update:
> UPDATE Account SET address={"street":"Melrose Avenue", "city":{"name":"Beverly Hills"}}
> UPDATE Profile SET nick='Luca' WHERE nick IS NULL LIMIT 20
> UPDATE Profile SET nick='Luca' UPSERT WHERE nick='Luca'
> UPDATE Counter INCREMENT viewes = 1 WHERE page='/downloads/' LOCK RECORD
UPDATE ♯7:0 SET gender='male' RETURN AFTER @rid
UPDATE ♯7:0 SET gender='male' RETURN AFTER @version
UPDATE ♯7:0 SET gender='male' RETURN AFTER @this
UPDATE ♯7:0 INCREMENT Counter = 123 RETURN BEFORE $current.Counter
UPDATE ♯7:0 SET gender='male' RETURN AFTER $current.exclude("really_big_field")
UPDATE ♯7:0 ADD out_Edge = ♯12:1 RETURN AFTER $current.outE("Edge")
In case a single field is returned, the result is wrapped in a record storing value in "result" field (Just to avoid introducing new serialization – there is no primitive-values collection serialization in binary protocol). Additionally to that, useful fields like version and rid of original record is provided in corresponding fields. New syntax will allow optimizing client-server network traffic.
To know more about the SQL syntax used in Orient, take a look at: SQL-Query.