如何在DynamoDB中创建复合GSI PK?

发布于 2025-02-09 23:03:18 字数 745 浏览 2 评论 0原文

我尝试使用使用 business_ID,type_id,pantch_id 字段的PK创建GSI。我在AWS控制台中以两种不同的方式进行了操作:

首先:business_id#type_id#pantch_id 第二个:[business_id]#[type_id]#[pharts_id]

and key:更新已更新

这是查询:

 SELECT *
 FROM "items"."composite_key-index" 
 WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
 ORDER BY updated ASC

在两种情况下,它都会引发此错误:

验证exception:必须至少具有一个非访问的哈希密钥 使用订单时条件在Where子句中的条件。

如果我在没有订单的情况下运行它:

 SELECT *
 FROM "items"."composite_key-index" 
 WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528

即使有数据匹配这些值,也不会返回任何项目。

我在这里做错了什么?

I have tried creating GSI with a PK that uses a composite value of business_id, type_id, partner_id fields. I did it in two different ways in the AWS console:

First: business_id#type_id#partner_id
Second: [business_id]#[type_id]#[partner_id]

and sort key: updated

Here is the query:

 SELECT *
 FROM "items"."composite_key-index" 
 WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528
 ORDER BY updated ASC

In both cases it throws this error:

ValidationException: Must have at least one non-optional hash key
condition in WHERE clause when using ORDER BY clause.

And if I run it without the order by:

 SELECT *
 FROM "items"."composite_key-index" 
 WHERE business_id = 435634652 AND type_id = 2 AND partner_id = 69992528

it doesnt return any items, even though there are data matching those values.

What am I doing wrong here?

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

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

发布评论

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

评论(1

樱娆 2025-02-16 23:03:18

要使用复合值作为键,您必须自己构建值。

您的应用程序必须将值存储在单个属性中,例如435634652#2#6992528

然后您的查询看起来像

SELECT *
 FROM "items"."composite_key-index" 
 WHERE GSI_PK = "435634652#2#6992528"

To use a composite value as a key, you have to build the values yourself.

Your application would have to store the value in a single attribute, ex GSI_PK, as 435634652#2#6992528

Then your query would look like

SELECT *
 FROM "items"."composite_key-index" 
 WHERE GSI_PK = "435634652#2#6992528"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文