DynamoDB: What's the difference, am I setting the attribute "NULL": "true" or just omitting it?

I have some elements that I insert like this:

PutItem:

"TableName": "pets", "Item": { "petName": { "S": "Cat" }, "hairColor": { "S": "gray" }, "nickName": { "S": "Kitty" } } 

Sometimes, however, pets do not have a nickname . I am new to dynamoDB, and I see that I can handle this in two ways (at least):

1)

 "TableName": "pets", "Item": { "petName": { "S": "Cat" }, "hairColor": { "S": "gray" }, "nickName": { "NULL": "true" } } 

2)

 "TableName": "pets", "Item": { "petName": { "S": "Cat" }, "hairColor": { "S": "gray" } } 

What is the difference for me (for example, when accessing data after that)? And what is the best practice?

+5
source share
1 answer

Setting the attribute to "NULL" or its absence is different from .

If you do not set an attribute at all, it obviously does not exist on a particular element. An attribute with a data type of "NULL", however, exists but does not contain a value (similar to null in JSON).

eg. when comparing with the null comparison operator, an attribute with the "NULL" property will actually be false. Naming is very confusing here, but the behavior is pretty well documented . For the comparison operator null it says:

This statement verifies that the attribute does not exist, and not its data type. If the data type of attribute "a" is NULL, and you evaluate it using NULL, the result is a boolean false. This is because the attribute “a” exists; its data type is not related to the NULL comparison operator.

+1
source

All Articles