AWS News Blog

Amazon SimpleDB – Now With Select

There’s now a new and somewhat easier way to write SimpleDB queries.

In addition to SimpleDB’s existing query language, you can now use select statements which look very similar to standard SQL (Structured Query Language). We made some small changes and additions to the language in order to accomodate SimpleDB’s unique multi-valued attribute model.

Here are some valid select statements:

select * from mydomain where city = ‘Seattle’
select * from mydomain where city = ‘Seattle’ or city = ‘Portland’
select * from mydomain where author not like ‘Henry%’

Things get even more interesting once multi-valued atttibutes are used. This query returns the items where the only attribute value for keyword is ‘Book’:

select * from mydomain where every(keyword) = ‘Book’

The following query returns items where the only value for keyword is ‘Book’ or Paperback’:

select * from mydomain where every(keyword) in (‘Book’, ‘Paperback’)

And the following query returns all the items which have the values ‘Book’ and ‘Hardcover’ in keyword:

select * from mydomain where keyword = ‘Book’ intersection keyword = ‘Hardcover’

You can also sort the results on any of the attributes that was used in the expression:

select * from mydomain where Year = ‘2007’ intersection Author is not null order by Author desc

The new SimpleDB Select function accepts queries in this new syntax. The existing Query and QueryWithAttributes functions are still usable, of course. There’s full information in the new version of the Developer Guide.

–Jeff;

TAGS:
Jeff Barr

Jeff Barr

Jeff Barr is Chief Evangelist for AWS. He started this blog in 2004 and has been writing posts just about non-stop ever since.