gpt4 book ai didi

amazon-dynamodb - DynamoDB : What difference does it make whether I set an attribute to "NULL": "true" or just omit it?

转载 作者:行者123 更新时间:2023-12-04 15:41:48 25 4
gpt4 key购买 nike

我有一些我像这样插入的项目:

放置项:

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

然而,有时, pets没有 nickname .我对 dynamoDB 很陌生,我可以看到,我可以通过两种方式(至少)处理这个问题:

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

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

这对我有什么不同(例如,在之后访问数据时)?最佳实践是什么?

最佳答案

将属性设置为“NULL”或省略它 不一样 .

如果您根本不设置属性,则该属性显然不存在于特定项目上。数据类型为“NULL”的属性 存在但不包含任何值(类似于 JSON 中的 null)。

例如。与比较运算符 NULL 进行比较时具有“NULL”属性的属性实际上是假的。这里的命名非常困惑,但行为相当well documented .对于比较运算符 NULL它说:

This operator tests for the nonexistence of an attribute, 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 relevant to the NULL comparison operator.

关于amazon-dynamodb - DynamoDB : What difference does it make whether I set an attribute to "NULL": "true" or just omit it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37325862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com