Search code examples
amazon-dynamodb

Extract part of composite sort key in DynamoDB projection


I have a composite sorting key as "123#xyz". I want to return only the first part of this key to the user.
Is it possible to use projection in a query to extract substring of a field?


Solution

  • No, projection expression can only return the entire value. What you need to do is split those values manually into two separate attributes which you can later decide to project.

    PK SK partA partB
    somepk 123#xyz 123 xyz