The only way to retrieve multiple items at a time, along with their attributes, from Amazon SimpleDB is with the Select operation. Typically, you query for some property of the items which you want to retrieve, not by item name:

select * from my_domain where date > '2009-01-01'

The only documented way to retrieve the attributes of an item by item name is with the GetAttributes operation, which only gets one item at a time. But what if you have a list of item names you want to retrieve, and you just want to avoid the overhead of making a separate GetAttributes call for each one?

A clue towards the solution can be found in the fact that the special itemName() token can be used in the field list for Select:

select itemName() from my_domain where date > '2009-01-01'

I didn't find this explicitly documented anywhere, but you can also use itemName() in a query condition:

select * from my_domain where itemName() = 'ABC123'

…and from there it’s a short step to our solution, which uses the IN predicate:

select * from my_domain where itemName() in ('ABC123', 'DEF456', ...)

And there you have it, a way to retrieve multiple items by name in a single request, subject only to limits on query size and response size. I don’t know if this is common knowledge to longtime SimpleDB users, but it was new to me, so I thought I’d share it.

Published by Avdi Grimm

4 Comments

  1. Pleased to report that M/DB supports this mechanism too 🙂

    Reply
  2. Thank you! I spent 3h to figure out how to do that! Simple itemName()…

    Reply
  3. Thank you! I spent 3h to figure out how to do that! Simple itemName()…

    Reply
  4. Thank you – this was a big help. Documentation is still sparse on SimpleDB.

    Reply

Leave a Reply to Peter Cancel reply

Your email address will not be published. Required fields are marked *