Prerna shah
Prerna shah

Reputation: 321

Query dynamoDB with IN operator on Partition Key

I have a table named products. It’s schema is

  1. CustomerNumber (HASH Key of type String)
  2. ProductID (Range Key of type String)

I want to query similar to

SELECT * FROM products WHERE CustomerNumber IN ("cust123","cust234"). 

How to achieve it?

Few observations -

  1. DynamoDBQueryExpression would query only on index/hashKey not not on list of hashKeys like in example above.

  2. Also DynamoDBQueryExpression doesnt support IN , OR operator.

  3. Also BatchLoad uses only Primary Key (in my case customerNumber and productID)record to return batch of records.

  4. Also ,I dont want to scan the table and apply filter on it.

  5. Also creating GSI on customerNumber and then querying it didn't work

Upvotes: 2

Views: 2232

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7669

Instead of select * where partitionkey IN ... you would do a separate query equivalent to select * where partitionkey= ... for each value of your IN condition. It costs you a few extra round trips on the network, but that’s all; if you’re concerned about speed you can execute the individual queries in parallel.

Upvotes: 6

Related Questions