Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamo DB + In put Item Request how to pass null value?

I have one field which i have declared as string in the model as show below:

App.Student= DS.Model.extend({
name: DS.attr('string'),
address1: DS.attr('string'),
address2: DS.attr('string'),
city: DS.attr('string'),
state: DS.attr('string'),
postal: DS.attr('string'),
country: DS.attr('string'),
});

Here in the Edit mode when i update Adderess 2 field as null then below error comes:

"Failed to edit property: One or more parameter values were invalid: An AttributeValue may not contain an empty string"

I know this Error is generated because i am updating address 2 field as null and that what i want Address 2 field is not mandatory(One can pass data or can also left that column as blank")

like image 211
Trilok Pathak Avatar asked Jul 01 '15 08:07

Trilok Pathak


People also ask

Does DynamoDB accept null values?

Dynamodb can't accept a key with an explicitly NULL value.

Can DynamoDB hash key null?

Can the DynamoDB sort key be null? DynamoDB does not support null for sort key.

Does DynamoDB accept empty string?

Empty value support gives you greater flexibility to use attributes for a broader set of use cases without having to transform such attributes before sending them to DynamoDB. List, Map, and Set data types also support empty String and Binary values.

Does DynamoDB PutItem overwrite?

By default, the DynamoDB write operations ( PutItem , UpdateItem , DeleteItem ) are unconditional: Each operation overwrites an existing item that has the specified primary key.


2 Answers

AWS finally resolved this issue. DynamoDb now supports empty string values for non-key attributes: https://aws.amazon.com/about-aws/whats-new/2020/05/amazon-dynamodb-now-supports-empty-values-for-non-key-string-and-binary-attributes-in-dynamodb-tables/

like image 95
kev Avatar answered Sep 23 '22 09:09

kev


If you are using DynamoDB (not DocumentClient) you can specify nulls like this

const putItem: PutItemInput = {
  TableName: `${process.env.PRIMARY_TABLE}`,
  Item: {
    key: { S: ${userId}` },
    someField: { NULL: true }
  }
}
like image 37
Zayin Krige Avatar answered Sep 25 '22 09:09

Zayin Krige