从日期boto订购的DynamoDB中返回所有项目

发布于 2025-02-11 07:31:54 字数 496 浏览 1 评论 0原文

我试图从DynamoDB表中返回所有项目,并按日期排序。表结构是:

IDDATE类别电子邮件错误ISREAD消息

,ID作为主密钥,将日期定义为“排序密钥”。

据我了解,无法订购扫描()操作,因此我试图使用打开查询。

我已经能够构建一个可以轻松返回特定ID的查询,但是我找不到仅允许查询返回所有内容的示例,可能会使用通配符?

response = table.query(KeyConditionExpression=Key('_id').eq('e2c0cad8-7630-48c6-8fc3-6b579d5ca021'))

是否有一种方法可以简单地基于可以返回有序列表而无需特定过滤器的键的密钥查询?

I am attempting to return all items from a dynamodb table with results ordered by date. The tables structure is:

IDDateCategoryEmailErrorsIsReadMessage

With ID as the primary key and date defined as the sort key.

As I understand it, a scan() operation cannot be ordered so I am attempting to utilise an open query instead.

I have been able to construct a query that can easily return a particular ID but I am unable to find examples that simply allow a query to return all, possibly using a wildcard?

response = table.query(KeyConditionExpression=Key('_id').eq('e2c0cad8-7630-48c6-8fc3-6b579d5ca021'))

Is there an approach that will simply allow a query based on a key that can return an ordered list without requiring a specific filter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2025-02-18 07:31:54

由于日期定义为排序键,因此使用GraphQl调用应该可以使用。而不是查询或扫描,请尝试使用执行。我的python有点生锈,但基本上是这样的:

response = client.execute_statement(
    Statement='SELECT * FROM "TABLE_NAME" WHERE "_id" = "e2c0cad8-7630-48c6-8fc3-6b579d5ca021" ORDER BY date DESC',
    Parameters=[
        {
            ...
        },
    ],
    ReturnConsumedCapacity='TOTAL'
)

据我所记得的,这些调用在RCU/WCU消耗中也有些轻一些。不过,请仔细检查响应中的returnConsumedCapacity。

dyanamodb UI还具有内置的partiql编辑器来帮助构建这些查询。

Since date is defined as the sort key, this should be possible using a GraphQL call. Instead of Query or Scan, try using ExecuteStatement. My Python is a little rusty, but basically something like this:

response = client.execute_statement(
    Statement='SELECT * FROM "TABLE_NAME" WHERE "_id" = "e2c0cad8-7630-48c6-8fc3-6b579d5ca021" ORDER BY date DESC',
    Parameters=[
        {
            ...
        },
    ],
    ReturnConsumedCapacity='TOTAL'
)

From what I remember, these calls are a little lighter on the RCU/WCU consumption as well. Double check that with the ReturnConsumedCapacity on the response though.

The DyanamoDB UI also has the built-in PartiQL editor to help with building these queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文