forked from orientechnologies/orientdb
-
Notifications
You must be signed in to change notification settings - Fork 0
SQLUpdate
jazzzz edited this page Dec 13, 2012
·
4 revisions
Update one or more records into the current database. Remember that Orient can work also in schema-less mode, so you can create any field at-the-fly. Furthermore OrientDB works on collection. This is the reason why the SQL has some extension to handle collections.
UPDATE <class>|cluster:<cluster>> SET|INCREMENT [= <field-value>](<field-name>)[<field-name> = <field-value>](,)* [<conditions>] (WHERE) [<max-records>](LIMIT)
Where:
- SET updates the field
- INCREMENT increments the field by the value. If the record had 10 as value and "INCREMENT value = 3" is executed, then the new value will be 13. This is useful for atomic updates of counters. Use negative numbers to decrement.
For COLLECTIONS:
UPDATE <class>|cluster:<cluster>> [[<field-name> = <field-value>](ADD|REMOVE])[<field-name> = <field-value>](,)* [<conditions>](WHERE)
For MAPS:
UPDATE <class>|cluster:<cluster>> [[<field-name> = <map-key> [,<map-value>]](PUT|REMOVE])[<field-name> = <map-key> [,<map-value>]](,)* [<conditions>](WHERE)
Note that RecordID must be prefixed with '#'. Example: #12:3.
To know more about conditions look at WHERE conditions.
> 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
To know more about the SQL syntax used in Orient take a look to: SQL Query.