dynamodb时间戳保留的名称expression-attribute-name

时间:2019-04-22 07:41:19

标签: amazon-dynamodb

DynamoDb表结构:

Primary key: userId, Sort key: timestamp

我创建了此查询:

aws dynamodb query \
    --table-name QAClusteredData \
    --key-condition-expression 'userId= :user_id AND timestamp BETWEEN :t1 AND :t2' \
    --expression-attribute-values '{
        ":user_id": {"S": "ec2e598f-cff8-4648-a120-3baf18e5102c"}, 
        ":t1": {"S": "1550481826"}, 
        ":t2": {"S": "1550662412"}
    }' \
    --region us-east-1

已收到:"An error occurred (ValidationException) when calling the Query operation: Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: timestamp"

尝试:

aws dynamodb query \
    --table-name QAClusteredData \
    --key-condition-expression 'userId= :user_id AND timestamp BETWEEN :t1 AND :t2' \
    --expression-attribute-names '{"#ts":"timestamp"}' \
    --expression-attribute-values '{
        ":user_id": {"S": "ec2e598f-cff8-4648-a120-3baf18e5102c"}, 
        ":t1": {"S": "1550481826"}, 
        ":t2": {"S": "1550662412"}
    }' \
    --region us-east-1

仍然出现相同的错误,有什么建议吗?

2 个答案:

答案 0 :(得分:1)

我不好,

必须放置#ts BETWEEN :t1 AND :t2而不是timestamp BETWEEN :t1 AND :t2

完整查询:

aws dynamodb query \
    --table-name QAClusteredData \
    --key-condition-expression 'userId= :user_id AND #ts BETWEEN :t1 AND :t2' \
    --expression-attribute-names '{"#ts":"timestamp"}' \
    --expression-attribute-values '{
        ":user_id": {"S": "ec2e598f-cff8-4648-a120-3baf18e5102c"}, 
        ":t1": {"S": "1550481826"}, 
        ":t2": {"S": "1550662412"}
    }' \
    --region us-east-1

答案 1 :(得分:0)

您的代码包含一个禁止的关键字::user_id AND timestamp BETWEEN :t1 AND :t2'

timestamp是DynamoDB中的保留字。以下是DynamoDB中保留关键字的列表:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html