Queries
SQL Queries against the tables that represent Amazon SimpleDB domains are very similar to any other SQL queries (see Using ADO.NET). In most simple cases the syntax you would expect to work will work right away, in some instances it might be useful to refer to Amazon SimpleDB syntax.
SimpleDB Query Syntax
The Amazon SimpleDB Query syntax is described in detail here>. We repeat some of the major elements described in the article.select output_list from table [where expression] [sort_instructions] [limit limit
The output_list can be any of the following:
- * (all attributes)
- count(*)
- An explicit list of attributes (column1,..., columnN)
The table is the domain to search.
The expression is the match expression.
The sort_instructions describe how to sort the results.
The limit is the maximum number of results to return (default: 100, max. 250).
The expression can be any of the following:
- select expression intersection select expression
- NOT select expression
- (select expression)
- select expression or select expression
- select expression and select expression
- simple comparison
SimpleDB Column Names
Column values must be quoted with a single or double quote. If a quote appears within the column value, it must be escaped with the same quote symbol.select * from mydomain where attr1 = 'He said, "That''s the ticket!"'
Column names and table names may appear without quotes if they contain only letters, numbers, underscores (_), or dollar symbols ($) and do not start with a number. You must quote all other column and table names with the backtick (`).
select * from mydomain where `timestamp-1` > '1194393600'
SimpleDB Comparison Operators
Amazon SimpleDB supports the following comparison operators:| = | Column equals the specified constant |
| != | Column does not equal the specified constant |
| < | Column is less than the specified constant |
| > | Column is greater than the specified constant |
| <= | Column is less than or equal to the specified constant |
| >= | Column is greater than or equal to the specified constant |
| like | Column value starts with the specified constant. Note: The like operator is similar to starts-with and only supports % at the end of the string. |
| not like | Column value does not start with the specified constant. Note: The like operator is similar to starts-with and only supports % at the end of the string. |
| between | Column value falls within a range, including the start and end value. |
| in | Column value is equal to one of the specified constants. |
| is null | Column does not exist. If a row has the column 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. |
| is not null | Column value contains any value. |