在AWS DynamoDb上查询Range键的最大值 [英] Querying for greatest value of Range key on AWS DynamoDb

查看:285
本文介绍了在AWS DynamoDb上查询Range键的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是DynamoDB等效项?

What is the DynamoDB equivalent of

SELECT MAX(RANGE_KEY) FROM MYTABLE WHERE PRIMARYKEY = "value"

我能想到的最好的是

from boto.dynamodb2.table import Table as awsTable

tb = awsTable("MYTABLE")
rs = list(tb.query_2(PRIMARYKEY__eq="value", reverse=True, limit=1))
MAXVALUE = rs[0][RANGE_KEY]

有更好的方法吗?

推荐答案

那是正确的方法。

由于哈希键匹配的记录按范围键排序,因此按后代顺序获得第一个记录将为您提供最大范围键的记录。 / p>

Because the records matched by the Hash Key are sorted by the Range Key, getting the first one by the descendant order will give you the record with the maximum range key.


查询结果始终按范围键排序。如果
范围键的数据类型为Number,则结果以数字顺序返回;否则,结果以数字顺序返回。
,否则,将按ASCII字符代码
值的顺序返回结果。默认情况下,排序顺序为升序。要反转订单
,请使用ScanIndexForward参数设置为false。

Query results are always sorted by the range key. If the data type of the range key is Number, the results are returned in numeric order; otherwise, the results are returned in order of ASCII character code values. By default, the sort order is ascending. To reverse the order use the ScanIndexForward parameter set to false.

查询和扫描操作-Amazon DynamoDB: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html

Query and Scan Operations - Amazon DynamoDB : http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html

注意:通过boto API将 reverse 参数设置为true等同于设置 ScanIndexForward 通过本地AWS API设置为false。

NOTE: Setting the reverse parameter to true via boto API is equivalent to setting ScanIndexForward to false via the native AWS API.

这篇关于在AWS DynamoDb上查询Range键的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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