druybew06513 2019-05-20 22:31
浏览 59
已采纳

不支持查询关键条件

I am trying to get all rows past a certain time stamp.

I have also tried using "GE", "LE", "GT" in the condition but I get a syntax error.

I get the following DynamoDB error:

Internal Server Error [ValidationException: Query key condition not supported
    status code: 400,

I have the following table

Table name  GroupsLambda3
Primary partition key   id (String)
Primary sort key    -
Point-in-time recovery  DISABLEDEnable
Encryption Type DEFAULTManage Encryption
KMS Master Key ARN  Not Applicable
Time to live attribute  DISABLEDManage TTL

Then I have created asecondary index on

Name: unix_time-index
Status: Active
Type: GSI
Partition Key: unix_time (Number)
Sort Key: unix_time-index

Finally my Golang code is:

    var cond string
    cond = "unix_time <= :v_unix_time"
    var projection string
    projection = "id, num_users, salesforce_campaign, unix_time"
    input := &dynamodb.QueryInput{
        TableName:              aws.String(table),
        IndexName:              aws.String("unix_time-index"),
        KeyConditionExpression: &cond,
        ProjectionExpression:   &projection,
        ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
            ":v_unix_time": {
                N: aws.String("1558130473454419"),
            },
        },

The code works when I do cond = "unix_time = :v_unix_time", equals only.

I expect all rows with a lesser unix_timestamp.

  • 写回答

1条回答 默认 最新

  • dpojoxa5613 2019-05-21 07:13
    关注

    You should use expression Builder:

    // todo: please check if value should be converted to another type in your case
    keyCond := expression.Key("unix_time").LessThenEqual(expression.Value("1558130473454419"))
    proj := expression.NamesList(expression.Name("id"), expression.Name("num_users"), expression.Name("salesforce_campaign"), expression.Name("unix_time"))
    
    expr, err := expression.NewBuilder().
        WithKeyCondition(keyCond).
        WithProjection(proj).
        Build()
    if err != nil {
        fmt.Println(err)
    }
    
    input := &dynamodb.QueryInput{
        ExpressionAttributeValues: expr.Values(),
        KeyConditionExpression:    expr.KeyCondition(),
        ProjectionExpression:      expr.Projection(),
        TableName:                 aws.String(table),
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题