DynamoDB 列表数据类型问题
DynamoDB List data-type issue
根据此 doc,DynamoDB 支持映射 (M) 和列表 (L) 类型,但是当我尝试创建具有 (L) 类型的 table 时,我得到一个错误:
ValidationException (client): 1 validation error detected: Value 'L' at 'attributeDefinitions.2.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]
将 ThreadReplyIds
属性添加到 Table 信息后发生:
[
'AttributeDefinitions' => [
[
'AttributeName' => 'UserId',
'AttributeType' => 'N',
],
[
'AttributeName' => 'ThreadReplyIds', // <<---
'AttributeType' => 'L',
],
[
'AttributeName' => 'Title',
'AttributeType' => 'S',
],
],
'KeySchema' => [
[
'AttributeName' => 'UserId',
'KeyType' => 'HASH',
],
[
'AttributeName' => 'Title',
'KeyType' => 'RANGE',
],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5,
],
'TableName' => 'Thread',
]
我的目标是为 ThreadReplyIds
存储一个列表或一组整数值。
我做错了什么?
起初,我以为这可能是您使用的SDK版本问题。但是在阅读了文档之后,似乎在创建 table 时,任何 AttributeDefinition 的 AttributeType 只能是 'S|N|B' 之一(意思是 'String'、'Number' 或'Binary')。参考:PHP SDK DynamoDB AttributeDefinition.
这是有道理的,因为无论如何您都不能在 KeySchema 中使用列表。因此,在创建 table 时不必为您的列表定义属性。在创建 table 中放置或更新项目时,您始终可以将此属性添加到您想要的任何数据。看这里:PHP SDK DynamoDB PutItem
根据此 doc,DynamoDB 支持映射 (M) 和列表 (L) 类型,但是当我尝试创建具有 (L) 类型的 table 时,我得到一个错误:
ValidationException (client): 1 validation error detected: Value 'L' at 'attributeDefinitions.2.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]
将 ThreadReplyIds
属性添加到 Table 信息后发生:
[
'AttributeDefinitions' => [
[
'AttributeName' => 'UserId',
'AttributeType' => 'N',
],
[
'AttributeName' => 'ThreadReplyIds', // <<---
'AttributeType' => 'L',
],
[
'AttributeName' => 'Title',
'AttributeType' => 'S',
],
],
'KeySchema' => [
[
'AttributeName' => 'UserId',
'KeyType' => 'HASH',
],
[
'AttributeName' => 'Title',
'KeyType' => 'RANGE',
],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5,
],
'TableName' => 'Thread',
]
我的目标是为 ThreadReplyIds
存储一个列表或一组整数值。
我做错了什么?
起初,我以为这可能是您使用的SDK版本问题。但是在阅读了文档之后,似乎在创建 table 时,任何 AttributeDefinition 的 AttributeType 只能是 'S|N|B' 之一(意思是 'String'、'Number' 或'Binary')。参考:PHP SDK DynamoDB AttributeDefinition.
这是有道理的,因为无论如何您都不能在 KeySchema 中使用列表。因此,在创建 table 时不必为您的列表定义属性。在创建 table 中放置或更新项目时,您始终可以将此属性添加到您想要的任何数据。看这里:PHP SDK DynamoDB PutItem