是否可以在 DynamoDB 中通过查询或扫描对结果进行排序? [英] Is it possible to ORDER results with query or scan in DynamoDB?

查看:26
本文介绍了是否可以在 DynamoDB 中通过查询或扫描对结果进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 DynamoDB 中使用查询或扫描 API 对结果进行排序?

Is it possible to ORDER results with Query or Scan API in DynamoDB?

我需要知道 DynamoDB 是否有来自 SQL 查询的 ORDER BY 'field' 之类的东西?

I need to know if DynamoDB has something like ORDER BY 'field' from SQL queries?

谢谢.

推荐答案

虽然没有明确说明,但许多现实世界的用例显然需要排序,并且可以通过 相应的哈希和范围类型主键:

Not explicitly, however, ordering is obviously needed for many real world use cases and can be modeled by means of the Hash and Range Type Primary Key accordingly:

在这种情况下,主键由两个属性组成.首先属性是哈希属性,第二个是范围属性.Amazon DynamoDB 在散列上构建无序散列索引主键属性和范围主上的 排序范围索引关键属性.[强调我的]

In this case, the primary key is made of two attributes. The first attributes is the hash attribute and the second one is the range attribute. Amazon DynamoDB builds an unordered hash index on the hash primary key attribute and a sorted range index on the range primary key attribute. [emphasis mine]

然后,您可以使用此范围索引通过 查询 API 并通过 ScanIndexForward 参数指定索引的向前或向后遍历(即排序方向).

You can then use this range index to optionally request items via the RangeKeyCondition parameter of the Query API and specify forward or backward traversal of the index (i.e. the sort direction) via the ScanIndexForward parameter.

更新:您可以通过带有 本地二级索引 以同样的方式.

Update: You can order by an attribute with a local secondary index in the same way.

这篇关于是否可以在 DynamoDB 中通过查询或扫描对结果进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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