Is it possible to have multiple fields as range key?

Say I have a table where each row is uniquely identified by <A,B,C>

 A   |   B   |  C  |  D   |  E  |

where A is the primary hash key

and I want B and C to be the primary range keys.

How can I have more than 2 fields as a primary key in DynamoDB?


You can't have more than 2 fields as primary key in DynamoDB.

As a workaround you can create local secondary index for each field that you want to be a range key. But you will not be able to build query with multiple range keys simultaneously because DynamoDB can only use one index at a time.

Consider using filter expressions, you will probably end up using more read throughput (filtering is performed after data is received from db) than you need but get the desired results.

| improve this answer | |

Put a copy of B and C in the range field (as an extra column) and make that your range key like "B_C" and you can still also have separate columns for B and C if you need.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.