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

asked a month ago126 views
2 Answers
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
EXPERT
answered a month ago
0

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

AWS
answered a month ago
  • Thank you for the answer,
    But can I make an index on the Partition Key to use functions on that index ?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions