GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.voltactivedata.com — SET_FIELD() Using VoltDBSET_FIELD()SET_FIELD() — Returns a copy of a JSON-encoded string, replacing the specified field value. SynopsisSET_FIELD( column, field-name-path, string-value ) DescriptionThe SET_FIELD() function finds the specified field within a JSON-encoded string and returns a copy of the string with the new value replacing that field's previous value. Note that the SET_FIELD() function returns an altered copy of the JSON-encoded string — it does not change any column values in place. So to change existing database columns, you must use SET_FIELD() with an UPDATE statement. For example, assume the Product table contains a VARCHAR column Productinfo which for one row contains the following JSON string: {"product":"Acme widget",
"availability":"plenty",
"info": { "description": "A fancy widget.",
"sku":"ABCXYZ",
"part_number":1234},
"warehouse":[{"location":"Dallas","units":25},
{"location":"Chicago","units":14},
{"location":"Troy","units":67}]
}It is possible to change the value of the UPDATE Product SET Productinfo =
SET_FIELD(Productinfo,'availability','"limited"')
WHERE FIELD(Productinfo,'product') = 'Acme widget';The second argument to the SET_FIELD() function can be a simple field name, as in the previous example, In which case the function replaces the value of the top field matching the specified name. Alternately, you can specify a path representing a hierarchy of names separated by periods. For example, you can replace the SKU number by specifying "info.sku" as the second argument, or you can replace the number of units in the second warehouse by specifying the field path "warehouse[1].units". For example, the following UPDATE statement does both by nesting SET_FIELD commands: UPDATE Product SET Productinfo =
SET_FIELD(
SET_FIELD(Productinfo,'info.sku','"DEFGHI"'),
'warehouse[1].units', '128')
WHERE FIELD(Productinfo,'product') = 'Acme widget';Note that the third argument is the string value that will be inserted into the JSON-encoded string. To insert a
numeric value, you enclose the value in single quotation marks, as in the preceding example where '128' is used as the
replacement value for the Finally, the replacement string value can be any valid JSON value, including another JSON-encoded object or array. It does not have to be a scalar string or numeric value. ExampleThe following example uses the SET_FIELD() function to add a new array element to the warehouse field. UPDATE Product SET Productinfo =
SET_FIELD(Productinfo,'warehouse',
'[{"location":"Dallas","units":25},
{"location":"Chicago","units":14},
{"location":"Troy","units":67},
{"location":"Phoenix","units":23}]')
WHERE FIELD(Productinfo,'product') = 'Acme widget'; |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |