Amazon SimpleDB
Developer Guide (API Version 2009-04-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Comparison Operators

Comparison operators are applied to a single attribute and are lexicographical in nature. When designing an application, you should carefully think through storing data in its appropriate string representation. For more information, see Working with Numerical Data.

The following table shows all Amazon SimpleDB comparison operators.

Comparison OperatorDescriptionSelect Example
=Attribute value or itemName() equals the specified constant.

select * from mydomain where city = 'Seattle'

select * from mydomain where city = 'Seattle' or city = 'Portland'

!=Attribute value or itemName() does not equal to the specified constant.

select * from mydomain where name != 'John'

select * from mydomain where name != 'John' and name != 'Humberto'

>Attribute value or itemName() is greater than the specified constant.select * from mydomain where weight > '0034'
>=Attribute value or itemName() is greater than or equal to the specified constant.select * from mydomain where weight >= '065'
<Attribute value or itemName() is less than the specified constant.select * from mydomain where weight < '0034'
<=Attribute value or itemName() is less than or equal to the specified constant.select * from mydomain where year <= '2000'
like

Attribute value or itemName() contains the specified constant.

The like operator can be used to evaluate the start of a string ('string%'), the end of a string ('%string'), or any part of a string ('%string%').

Note

Using the like operator to evaluate the end of a string or any part of a string is an expensive operation. Make sure to combine it with other predicates to reduce number of items it has to evaluate.

To search for strings that contain the percent sign (%), you must escape it. For example, to search for a string that ends in '3%', you enter select * from mydomain where name like '%3\%'. To search for a string that begins with '3%', you enter select * from mydomain where name like '3\%%'. To search for a string that contains '3%', you enter select * from mydomain where name like '%3\%%'.

select * from mydomain where author like 'Henry%' select * from mydomain where keyword = 'Book' and author like '%Miller'

not like

Attribute value or itemName() does not contain the specified constant.

The not like operator can be used to evaluate the start of a string ('string%'), the end of a string ('%string'), or any part of a string ('%string%').

Note

Using the not like operator to evaluate the end of a string or any part of a string is an expensive operation. Make sure to combine it with other predicates to reduce number of items it has to evaluate.

select * from mydomain where author not like 'Henry%' select * from mydomain where keyword = 'Book' and author not like '%Miller'
betweenAttribute value or itemName() falls within a range, including the start and end value.select * from mydomain where year between '1998' and '2000'
inAttribute value or itemName() is equal to one of the specified constants. When used with items, in acts as a batch get. select * from mydomain where year in('1998','2000','2003') select * from mydomain where itemName() in('0385333498','0802131786','B000T9886K')
is nullAttribute does not exist. If an item has the attribute with an empty string, it is not returned.

Note

Due to performance issues, this operator is not recommended when most items have the specified attribute.

select * from mydomain where year is null
is not nullAttribute value or itemName() contains any value.select * from mydomain where year is not null
every()For multi-valued attributes, every attribute value must satisfy the constraint.

Note

Due to the cost of running more complex queries, this operator is only recommended for multi-valued attributes.

select * from mydomain where every(keyword) = 'Book'

select * from mydomain where every(keyword) like '***%'