不支持查询键条件

我试图让所有行都超过某个时间戳。


我也尝试在条件中使用“GE”、“LE”、“GT”,但出现语法错误。


我收到以下 DynamoDB 错误:


Internal Server Error [ValidationException: Query key condition not supported

    status code: 400,

我有下表


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

然后我创建了一个二级索引


Name: unix_time-index

Status: Active

Type: GSI

Partition Key: unix_time (Number)

Sort Key: unix_time-index

最后我的 Golang 代码是:


    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"),

            },

        },

当我这样做时,代码有效cond = "unix_time = :v_unix_time",仅等于。


我希望所有行都具有较小的 unix_timestamp。


慕码人2483693
浏览 117回答 1
1回答

慕容708150

您应该使用表达式生成器:// todo: please check if value should be converted to another type in your casekeyCond := 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().&nbsp; &nbsp; WithKeyCondition(keyCond).&nbsp; &nbsp; WithProjection(proj).&nbsp; &nbsp; Build()if err != nil {&nbsp; &nbsp; fmt.Println(err)}input := &dynamodb.QueryInput{&nbsp; &nbsp; ExpressionAttributeValues: expr.Values(),&nbsp; &nbsp; KeyConditionExpression:&nbsp; &nbsp; expr.KeyCondition(),&nbsp; &nbsp; ProjectionExpression:&nbsp; &nbsp; &nbsp; expr.Projection(),&nbsp; &nbsp; TableName:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aws.String(table),}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go