The SimpleDB service stores all content as text, including the attribute values that store your data. The service does not recognize data types in the same way that a relational database does. This feature makes the service more flexible, because you can store any values you like without having to worry about whether they match a predefined schema; however, it also means that the service is only able to compare or sort values based on lexicographical (alphabetical) ordering. Whereas a traditional database can compare various data types based on a full understanding of what the particular type means, SimpleDB is oblivious to the standard data types and will assume that an alphabetical ordering always makes sense.
If you intend to perform queries that use comparison operators, such as less-than and greater-than, you will have to carefully encode any nontextual data you store in the service so that its lexicographical ordering is the same as the expected ordering for data of that type. You will also need to be able to decode these text values when you retrieve them from SimpleDB.
In this section we will define methods to encode and decode the most commonly used data types: Boolean, date, integer, and float. Our data-type encodings are designed to meet two criteria:
The encoded values retain the expected ordering when sorted lexicographically.
Encoded values include a special prefix character (!), to make it easy to recognize them, and a second character to ...