Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Database
  • Getting started
    • Overview
    • Create databases
    • Examples of YQL queries
    • Examples of operations in the YDB CLI
    • Launch a test app
    • Document API
    • Developing in NodeJS through the Document API
  • Step-by-step instructions
    • Database management
    • How to connect to a database
    • Table management
    • Reading and writing data
    • Working with secondary indexes
  • Working with the SDK
  • Concepts
    • Overview
    • Data model and schema
    • Serverless and Dedicated operation modes
    • Data types
    • Transactions
    • Secondary indexes
    • Time to Live (TTL)
    • Terms and definitions
    • Quotas and limits
  • Access management
  • Pricing policy
    • Overview
    • Serverless mode
    • Dedicated mode
  • Recommendations
    • Schema design
    • Partitioning tables
    • Secondary indexes
    • Paginated output
    • Loading large data volumes
    • Using timeouts
  • YDB API and API reference
    • Database limits
    • Handling errors in the API
  • Amazon DynamoDB-compatible HTTP API
    • API reference
      • All methods
      • Actions
        • BatchGetItem
        • BatchWriteItem
        • CreateTable
        • DeleteItem
        • DeleteTable
        • DescribeTable
        • GetItem
        • ListTables
        • PutItem
        • Query
        • Scan
        • TransactGetItems
        • TransactWriteItems
        • UpdateItem
      • Common errors
  • YQL reference guide
    • Overview
    • Data types
      • Simple
      • Optional
      • Containers
      • Special
    • Syntax
      • Unsupported statements
      • For text representation of data types
      • Expressions
      • CREATE TABLE
      • DROP TABLE
      • INSERT INTO
      • UPSERT INTO
      • REPLACE INTO
      • UPDATE
      • DELETE
      • SELECT
      • GROUP BY
      • JOIN
      • FLATTEN
      • ACTION
      • DISCARD
      • PRAGMA
      • DECLARE
      • OVER, PARTITION BY, and WINDOW
    • Built-in functions
      • Basic
      • Aggregate
      • Window
      • For lists
      • For dictionaries
      • For JSON
      • For structures
      • For types
    • Preset user-defined functions
      • HyperScan
      • Pcre
      • Pire
      • Re2
      • String
      • Unicode
      • Datetime
      • Url
      • Ip
      • Digest
      • Math
      • Histogram
    • For text representation of data types
  • YQL tutorial
    • Overview
    • Creating a table
    • Adding data to a table
    • Selecting data from all columns
    • Selecting data from specific columns
    • Sorting and filtering
    • Data aggregation
    • Additional selection criteria
    • Joining tables by JOIN
    • Data insert and update by REPLACE
    • Data insert and update by UPSERT
    • Data insert by INSERT
    • Data update by UPDATE
    • Deleting data
    • Adding and deleting columns
    • Deleting a table
  • Maintenance
    • Backups
  • Diagnostics
    • System views
  • Questions and answers
    • General questions
    • Errors
    • YQL
    • All questions on the same page
  • Public materials
  1. Amazon DynamoDB-compatible HTTP API
  2. API reference
  3. Actions
  4. UpdateItem

UpdateItem method

  • Request
    • Parameters
  • Response
    • Parameters
  • Errors

Updates the attributes of an existing item or adds a new item if it doesn't exist. You can update, delete, or add attribute values.

You can set an update condition. The method is then triggered only if the condition is met.

It may return the attribute values that were valid before or after the update.

Request

The request contains data in JSON format.

{
   "AttributeUpdates": { 
      "string" : { 
         "Action": "string",
         "Value": { 
            "B": blob,
            "BOOL": boolean,
            "BS": [ blob ],
            "L": [ 
               "AttributeValue"
            ],
            "M": { 
               "string" : "AttributeValue"
            },
            "N": "string",
            "NS": [ "string" ],
            "NULL": boolean,
            "S": "string",
            "SS": [ "string" ]
         }
      }
   },
   "ConditionExpression": "string",
   "Expected": { 
      "string" : { 
         "AttributeValueList": [
            { 
               "B": blob,
               "BOOL": boolean,
               "BS": [ blob ],
               "L": [ 
                  "AttributeValue"
               ],
               "M": { 
                  "string" : "AttributeValue"
               },
               "N": "string",
               "NS": [ "string" ],
               "NULL": boolean,
               "S": "string",
               "SS": [ "string" ]
            }
         ],
         "ComparisonOperator": "string",
         "Exists": boolean,
         "Value": { 
            "B": blob,
            "BOOL": boolean,
            "BS": [ blob ],
            "L": [ 
               "AttributeValue"
            ],
            "M": { 
               "string" : "AttributeValue"
            },
            "N": "string",
            "NS": [ "string" ],
            "NULL": boolean,
            "S": "string",
            "SS": [ "string" ]
         }
      }
   },
   "ExpressionAttributeNames": { 
      "string" : "string" 
   },
   "ExpressionAttributeValues": { 
      "string" : { 
         "B": blob,
         "BOOL": boolean,
         "BS": [ blob ],
         "L": [ 
            "AttributeValue"
         ],
         "M": { 
            "string" : "AttributeValue"
         },
         "N": "string",
         "NS": [ "string" ],
         "NULL": boolean,
         "S": "string",
         "SS": [ "string" ]
      }
   },
   "Key": { 
      "string" : { 
         "B": blob,
         "BOOL": boolean,
         "BS": [ blob ],
         "L": [ 
            "AttributeValue"
         ],
         "M": { 
            "string" : "AttributeValue"
         },
         "N": "string",
         "NS": [ "string" ],
         "NULL": boolean,
         "S": "string",
         "SS": [ "string" ]
      }
   },
   "ReturnConsumedCapacity": "string",
   "ReturnValues": "string",
   "TableName": "string",
   "UpdateExpression": "string"
}

Parameters

Parameter Description
Key Primary key of the item to update, specify all the key attributes. For a simple primary key, you only need to specify its value. For a composite primary key, specify the value of the partition key and sort key.

Type: Associative array of the AttributeValue type.
Length: 1 - 65535 characters.
Required: Yes
TableName Name of the table storing the item to update.
May contain a path in the directory hierarchy like path/to/table.

Type: String
Length: 3 - 255 characters
Pattern: [a-zA-Z0-9_.-]+
Required: Yes
ConditionExpression Condition for updating the item. The method is only triggered if the condition is met.
The condition consists of:
  • Functions: attribute_exists | attribute_not_exists | attribute_type | contains | begins_with | size. Names of the following are case-sensitive.
  • Comparison operator: = | <> | < | > | <= | >= | BETWEEN | IN.
  • Logical operator: AND | OR | NOT.

Type: String
Required: No
ExpressionAttributeNames Placeholder that can be used in an expression instead of an attribute name. The placeholder must start with the hash character #.
Possible use cases:
  • If you need to specify an attribute whose name conflicts with the word reserved.
  • As a variable if the attribute name is used in an expression multiple times.
  • To prevent the misinterpretation of special characters in the attribute name.
For example, the attribute name Percentile conflicts with the reserved word and you can't use it in the expression explicitly. To get around this problem, in the ExpressionAttributeNames parameter, specify the placeholder: {"#P":"Percentile"}. Then, instead of the real attribute name, use #P.

Type: String
Length: 1 - 65535 characters.
Required: No
ExpressionAttributeValues Placeholder that can be used in an expression instead of an attribute value, similar to ExpressionAttributeNames. The placeholder must start with a colon :.
For example, you need to check whether the value of the ProductStatus attribute was one of the following: Available | Backordered | Discontinued. To do this, first declare placeholders: { ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} }. After that, you can use them in the expression: ProductStatus IN (:avail, :back, :disc)

Type: String of the AttributeValue type
Required: No
ReturnConsumedCapacity Indicates whether to return information about consumed capacity.
  • TOTAL: Return.
  • NONE: Do not return.

Type: String
Possible values: TOTAL | NONE
Required: No
ReturnValues Used if you need to get the attributes of an item before and after its update.
Possible values:
  • NONE: Do not return any attributes (default)
  • ALL_OLD: Return all attributes as they were before the update
  • UPDATED_OLD: Only return the updated attributes as they were before the update.
  • ALL_NEW: Return all attributes as they will look after the update.
  • UPDATED_NEW: Only return the updated attributes as they will look after the update.
No read capacity units are used in this case.
Returned values are strongly consistent.

Type: String
Possible values: NONE | ALL_OLD | UPDATED_OLD | ALL_NEW | UPDATED_NEW
Required: No
UpdateExpression Expression to update. Specifies how and which attributes to update.
Possible actions:
  • SET: Sets the attribute to the specified value. If no attribute exists, it will be created.
    Supported functions:
    • if_not_exists (path, operand): Checks that the specified attribute doesn't exist. If no attribute is found at the specified path, the function calculates the specified operand.
    • list_append (operand, operand): Evaluates to a list with a new element added to it. You can append the new element to the start or the end of the list by reversing the order of the operands.
    Function names are case-sensitive.
  • REMOVE: Removes attributes.
  • ADD: Adds a value to an attribute.
    If the attribute exists, the ADD function behavior depends on the attribute's data type:
    • If it's numeric, the addition operation is performed and the attribute value is added to the specified value. If the attribute or value didn't exist, then 0 is taken as the basis and used by the addition operation.
    • If the attribute is a set, the specified value is added to the set. Both sets (that in the attribute value and the one specified) must have the same data type.
  • DELETE Deletes an item from the set. Applicable to sets and top-level attributes only. You can't delete nested attributes.
    You can specify multiple items at a time.
A single expression may contain multiple actions, for example, SET a=:value1, b=:value2 DELETE :value3, :value4, :value5

Type: String
Required: No

Response

If successful, HTTP code 200 is returned.
The response is returned in JSON format.

{
   "Attributes": { 
      "string" : { 
         "B": blob,
         "BOOL": boolean,
         "BS": [ blob ],
         "L": [ 
            "AttributeValue"
         ],
         "M": { 
            "string" : "AttributeValue"
         },
         "N": "string",
         "NS": [ "string" ],
         "NULL": boolean,
         "S": "string",
         "SS": [ "string" ]
      }
   },
   "ConsumedCapacity": { 
      "CapacityUnits": number,
      "GlobalSecondaryIndexes": { 
         "string" : { 
            "CapacityUnits": number,
            "ReadCapacityUnits": number,
            "WriteCapacityUnits": number
         }
      },
      "LocalSecondaryIndexes": { 
         "string" : { 
            "CapacityUnits": number,
            "ReadCapacityUnits": number,
            "WriteCapacityUnits": number
         }
      },
      "ReadCapacityUnits": number,
      "Table": { 
         "CapacityUnits": number,
         "ReadCapacityUnits": number,
         "WriteCapacityUnits": number
      },
      "TableName": "string",
      "WriteCapacityUnits": number
   }

}

Parameters

Parameter Description
Attributes Associative array of the AttributeValue type containing an item's representation before or after it's updated.
Returned only if the request passed the ReturnValues parameter that wasn't set to NONE.

Type: Associative array of the AttributeValue type
Length: 1 - 65535 characters.
ConsumedCapacity Units of capacity consumed by a delete operation.
Returned only if the request passed the ReturnConsumedCapacity parameter set to TOTAL.

Type: Object type ConsumedCapacity type

Errors

Parameter Description
ConditionalCheckFailedException Can't check the condition specified in the operation.

HTTP status code: 400
InternalServerError An internal error occurred on the server side.

HTTP status code: 500
ProvisionedThroughputExceededException You're sending requests too often. Try to increase the interval between requests.
If their number is not too large, Yandex Database tries to process them all.

HTTP status code: 400
RequestLimitExceeded The bandwidth exceeds the set quota.

HTTP status code: 400
ResourceNotFoundException The specified table doesn't exist or isn't in the 'ACTIVE' state.

HTTP status code: 400
TransactionConflictException The operation is rejected as a different transaction is in progress for the item.

HTTP status code: 400

There may be common errors as well. These are errors that are common to all methods.

In this article:
  • Request
  • Parameters
  • Response
  • Parameters
  • Errors
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC