Working Remotely? Thinking about it?

Are you a member of a geographically dispersed team? Are you thinking of working remotely, or hiring remote developers? Wide Teams is my new blog and podcast for distributed teams. Check it out for getting started guides, tips and best practices, news, interviews, screencasts, and more all about working remotely and collaborating with wide-spread teams.

Fetching multiple SimpleDB items in a single request

2009 November 24
tags: ,
by avdi

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.

Bookmark and Share
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Related posts:

  1. Copying Amazon SimpleDB Domains
  2. The State of SimpleDB Clones
  3. ISO8601 Dates in Ruby
  4. Array-ifying Values
  5. First and Rest in Ruby
  • Peter
    Thank you! I spent 3h to figure out how to do that! Simple itemName()...
  • robtweed
    Pleased to report that M/DB supports this mechanism too :-)
blog comments powered by Disqus