dousi6303
2016-11-02 09:19
浏览 100
已采纳

如何在aws-sdk-go Dynamodb QueryInput中使用“ BETWEEN”?

I am using aws-sdk-go for dynamodb. I need to collect some items from my DB. The filtering conditions are deviceid: xyz, time >= 10 and time <= 20.

time is the sort key for my db and deviceid is the primary key. I understand I have to use BETWEEN for achieving my goal. My Implementations are not successful and as follows:

var queryInput = &dynamodb.QueryInput{
    TableName: aws.String(dbName),
    KeyConditions: map[string]*dynamodb.Condition{
        "deviceid": {
            ComparisonOperator: aws.String("EQ"),
            AttributeValueList: []*dynamodb.AttributeValue{
                {
                    S: aws.String("xyz"),
                },
            },
        },
        "time": {
            ComparisonOperator: aws.String("BETWEEN"),
            AttributeValueList: []*dynamodb.AttributeValue{
                {
                    N: aws.String("10"),
                    N: aws.String("20"),
                },
            },

        },
    },
}

What are the mistakes I made here?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan246558 2016-11-02 13:45
    已采纳

    The time value should be given as mentioned below:-

    "time": {
                ComparisonOperator: aws.String("BETWEEN"),
                AttributeValueList: []*dynamodb.AttributeValue{
                    {
                        N: aws.String("10"),                        
                    },
                    {
                        N: aws.String("20"),                        
                    },
                },
            },
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题