Is it possible to ORDER results with query or scan in DynamoDB?

前端 未结 6 765
长发绾君心
长发绾君心 2020-12-04 16:42

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

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

Tha

6条回答
  •  眼角桃花
    2020-12-04 17:02

    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:

    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]

    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.

提交回复
热议问题