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

feita há 2 meses137 visualizações
2 Respostas
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
ESPECIALISTA
respondido há 2 meses
0

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

AWS
respondido há 2 meses
  • Thank you for the answer,
    But can I make an index on the Partition Key to use functions on that index ?

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas