Amazon SimpleDB has now SELECT

Posted by Alin Irimie on December 18, 2008

Amazon SimpleDB gets easier and easier to use. And more powerful. It is now easy to write simple SQL like statements for your table (domain). Of course, there are changes and additions to the language in order to accomodate SimpleDB’s unique multi-valued attribute model.

Here’s what you can do:

SELECT * FROM users WHERE name = 'John' OR name LIKE 'Mark%'
SELECT * FROM users WHERE name NOT LIKE '%John%'

Attribute values must be quoted with a single or double quote. If a quote appears within the attribute value, it must be escaped with the same quote symbol (e.g., ‘You ain’’t no Picasso’).

Quoting attribute and domain names is optional if the name only contains letters, numbers, underscores (_), or dollar symbols ($) and does not start with a number. However, attribute and domain names that contain any other characters, such as spaces, must be quoted with escaped quotes (e.g., ‘Invisible’ Pink’ Unicorn’ Sightings’). 

SELECT `Invisible`` Pink`` Unicorn`` Sightings` from `My Domain` WHERE location = 'O''Brien, TX' AND `timestamp-1` > '' ORDER BY `timestamp-1`

Other examples of usage:
Usage of multi-valued attributes to query data


SELECT * from orders where every(keyword) = 'Dvd'

You can also sort the results


SELECT * from dvds where Year = '2008' intersection Director like 'Steve%' order by Director ASC

The following query returns items where the only value for keyword is ‘New Release’:

SELECT * FROM dvds WHERE EVERY(keyword) in 'New Release'

You can find more information in the Developer Guide.

Share it:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Live
  • NewsVine
  • TwitThis
  • StumbleUpon
  • Technorati

Related posts:

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments