按名为“timestamp"的列查询 Amazon DynamoDB(保留字) [英] Query an Amazon DynamoDB by column named "timestamp" (a reserved word)

查看:31
本文介绍了按名为“timestamp"的列查询 Amazon DynamoDB(保留字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为timestamp"的列的 DynamoDB 表,我正在尝试按日期查询.我无法控制更改列名.

I have a DynamoDB table with column named "timestamp" and am trying to query by date. I don't have control over changing the column name.

var params = {
    TableName : 'REPORT_CARD',

    KeyConditionExpression: "timestamp BETWEEN :startDate AND :endDate",
    ExpressionAttributeValues: {
        ":startDate": ""+startDate,
        ":endDate": ""+endDate
    }     
}

我收到错误:

错误:ValidationException:无效的 KeyConditionExpression:属性名称是保留关键字;保留关键字:时间戳

ERROR: ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: timestamp

除了重命名时间戳"列之外,还有其他解决方法吗?

Is there a workaround for this besides renaming the "timestamp" column?

推荐答案

首先,假设表'REPORT_CARD'定义为分区键timestamp,您只能在KeyConditionExpression中使用等式运算符(即'=')按分区键查询数据.

Firstly, assuming the table 'REPORT_CARD' is defined with partition key as timestamp, you can use only equality operator (i.e. '=') in KeyConditionExpression for querying data by partition key.

如果timestamp被定义为表格中的排序键,你可以使用BETWEEN.

You may use BETWEEN if the timestamp is defined as sort key in the table.

关于关键字错误,您可以使用ExpressionAttributeNames来提供属性名称timestamp.下面的例子:-

Regarding the keyword error, you can use ExpressionAttributeNames to provide the attribute name timestamp. Example below:-

var params = {
    TableName: 'REPORT_CARD',

    KeyConditionExpression: "parition_key_attr = :partition_val AND #timestamp BETWEEN :startDate AND :endDate",
    ExpressionAttributeNames: { "#timestamp": "timestamp" },
    ExpressionAttributeValues: {
        ':partition_val': "somevalue",
        ":startDate": startDate,
        ":endDate": endDate
    }

这篇关于按名为“timestamp"的列查询 Amazon DynamoDB(保留字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆