验证Exception:在使用订单条款时,必须至少有一个非访问的关键条件
我有此查询,可以根据这些条件获取所有消息:
SELECT id, message, created, sender_company_id, receiver_company_id, read_msg, receiver_user_id, receiver_user_name,
sender_user_name, sender_user_id, sender_company_name, receiver_company_name
FROM "messages"."sender_company_id-created-index"
WHERE (sender_company_id = 435634652 AND sender_user_id = 186)
OR (receiver_company_id = 435634652 AND receiver_user_id = 186) // if I remove this condition it works
ORDER BY created ASC, sender_company_id ASC
以下是我使用分类键创建的索引,以便我可以使用以下订单:
,如您在查询中所见,我是使用“ sender_company_id-greated-index”:
...FROM "messages"."sender_company_id-created-index"
如果我尝试仅使用第一个条件运行查询,则可以正常工作,但这不是我想做的,我希望这两个条件都在查询中。
这是当我尝试在AWS控制台中运行它时,它会引发的错误:
valivationException:在使用订单按子句时,必须至少有一个非访问的哈希关键条件。
是没有道理的。因为我实际上在使用可选的和非选项密钥作为条件。我看不到我在这里做错了什么,有人可以帮忙吗?
I have this query where I fetch all messages based on these conditions:
SELECT id, message, created, sender_company_id, receiver_company_id, read_msg, receiver_user_id, receiver_user_name,
sender_user_name, sender_user_id, sender_company_name, receiver_company_name
FROM "messages"."sender_company_id-created-index"
WHERE (sender_company_id = 435634652 AND sender_user_id = 186)
OR (receiver_company_id = 435634652 AND receiver_user_id = 186) // if I remove this condition it works
ORDER BY created ASC, sender_company_id ASC
Here are the indexes I have created with sorting keys so that I can use ORDER BY:
And as you can see in the query I am using "sender_company_id-created-index":
...FROM "messages"."sender_company_id-created-index"
If I try to run the query with only the first condition, it works but that's not what I want to do, I want both conditions to be in the query.
Here is the error it throws when I try to run it in the AWS console:
ValidationException: Must have at least one non-optional hash key condition in WHERE clause when using ORDER BY clause.
It doesnt make sense because I am actually using both, optional and non-optional keys as conditions. I cant see what am I doing wrong here, can someone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这两个条件都将是加入。 DynamoDB不支持这样的加入。您可以使用一个索引或另一个索引,但不能同时使用。
我建议您在此处进行两个查询(一个针对每个索引),然后在客户端加入结果。
To do both conditions would be a join. DynamoDB does not support joins like this. You can use one index OR the other, but not both at the same time.
I'd suggest you do two queries here (one against each index) and join the results on the client side.