GPUdb.update_records( table_name = None, expressions = None, new_values_maps =
None, records_to_insert = [], records_to_insert_str =
[], record_encoding = 'binary', options = {} )
Runs multiple predicate-based updates in a single call. With the list of given expressions, any matching record's column values will be updated as provided in input parameter new_values_maps. There is also an optional 'upsert' capability where if a particular predicate doesn't match any existing record, then a new record can be inserted.
Note that this operation can only be run on an original table and not on a collection or a result view.
This operation can update primary key values. By default only 'pure primary key' predicates are allowed when updating primary key values. If the primary key for a table is the column 'attr1', then the operation will only accept predicates of the form: "attr1 == 'foo'" if the attr1 column is being updated. For a composite primary key (e.g. columns 'attr1' and 'attr2') then this operation will only accept predicates of the form: "(attr1 == 'foo') and (attr2 == 'bar')". Meaning, all primary key columns must appear in an equality predicate in the expressions. Furthermore each 'pure primary key' predicate must be unique within a given request. These restrictions can be removed by utilizing some available options through input parameter options.
Input Parameter Description
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
table_name | str | Table to be updated. Must be a currently existing table and not a collection or view. | ||||||||||
expressions | list of str | A list of the actual predicates, one for each update; format should follow the guidelines here. | ||||||||||
new_values_maps | list of dicts of str, and None | List of new values for the matching records. Each element is a map with (key, value) pairs where the keys are the names of the columns whose values are to be updated; the values are the new values. The number of elements in the list should match the length of input parameter expressions. | ||||||||||
records_to_insert | list of str | An optional list of new binary-avro encoded records to insert, one for each update. If one of input parameter expressions does not yield a matching record to be updated, then the corresponding element from this list will be added to the table. Default value is an empty list ( [] ). | ||||||||||
records_to_insert_str | list of str | An optional list of new json-avro encoded objects to insert, one for each update, to be added to the set if the particular update did not affect any objects. Default value is an empty list ( [] ). | ||||||||||
record_encoding | str | Identifies which of input parameter records_to_insert and input parameter records_to_insert_str should be used. Default value is 'binary'. The allowed values are:
|
||||||||||
options | dict of str | Optional parameters. Default value is an empty dict ( {} ).
|
Output Parameter Description
Name | Type | Description |
---|---|---|
count_updated | long | Total number of records updated. |
counts_updated | list of longs | Total number of records updated per predicate in input parameter expressions. |
count_inserted | long | Total number of records inserted (due to expressions not matching any existing records). |
counts_inserted | list of longs | Total number of records inserted per predicate in input parameter expressions (will be either 0 or 1 for each expression). |