Search code examples
amazon-dynamodbdynamodb-queriesamazon-dynamodb-index

DynamoDB intersection select with pagination


I have following DB schema and I'd like to find the best way how to select list of Sorted keys which are common for PK_A and PK_B:

+---------------+---------+
|      PK       | SortKey |
+---------------+---------+
|               | SK_A    |
| PK_A          | SK_B    |
|               | SK_C    |
| - - - - - - - |         |
|               | SK_B    |
| PK_B          | SK_C    |
|               | SK_D    |
+---------------+---------+

so when I do select by PK_A and PK_B it should return me only SK_B and SK_C?

Any help is appreciated.


Solution

  • Simple answer, you can't do it (in one call).

    Dynamo is not a relational database, operations such as intersection are not supported.

    You'd need to query() once for each partition key and then calculate the intersect yourself.