DynamoDB query Partition Key with functions

0

Hello,

Is it possible to query DynamoDB table on its Partition Key with a function, like in the below example, or do I need an index ?

QuerySpec spec = new QuerySpec()
    			.withKeyConditionExpression("begins_with(PicturePK, :v_prefix) ")
    			.withValueMap(new ValueMap() 
    			         .withString(":v_prefix", prefix));

Thank you,
Mihai ADAM

已提问 2 个月前137 查看次数
2 回答
2

As Jason states, you cannot use a function on the partition key. But you can add a GSI which can help your achieve the use-case. This blog post outlines how you can achieve that.

GSI data:

PKPicturePKData
1123Data
1321Data
1355Data
QuerySpec spec = new QuerySpec()
    			.withKeyConditionExpression("PK = :pk AND begins_with(PicturePK, :v_prefix) ")
    			.withValueMap(new ValueMap() 
    			         .withString(":v_prefix", prefix)
                                 .withNumber(":pk", "1"));
profile pictureAWS
专家
已回答 2 个月前
0

With a query the partition key must be specified exactly. Sort keys can use begins_with.

AWS
已回答 2 个月前
  • Thank you for the answer,
    But can I make an index on the Partition Key to use functions on that index ?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则