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 ?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠