0

I'm trying to use SQL IN clause kind of feature in dynamoDB. I tried using withFilterExpression but I'm not sure how to do it. I looked at similar questions as they were too old. Is there a better method to do this? This is the segment of code I have got. I have used a static List as example but it is actually dynamic.

def getQuestionItems(conceptCode : String) = {

  val qIds = List("1","2","3")

  val querySpec = new QuerySpec()
  .withKeyConditionExpression("concept_id = :c_id")
  .withFilterExpression("question_id in :qIds") // obviously wrong
  .withValueMap(new ValueMap()
    .withString(":c_id", conceptCode));
 questionsTable.query(querySpec);
}

I need to pass qID list to fetch results similar to IN clause in SQL Query.

1 Answer 1

1

Please refer to this answer. Basically you need to form key list/value list dynamically

.withFilterExpression("question_id in (:qId1, :qId2, ... , :qIdN)")
.withValueMap(new ValueMap()
    .withString(":qId1", ..) // just do this for each element in the list in a loop programmatically
    ....
    .withString(":qIdN", ..)
);

Mind there is a restriction on maxItems in 'IN'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.