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 ?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ