DynamoDB supports boolean, byte, int, long, float and double primitive data types. It also supports wrapper classes for these primitive data types, such as Boolean, Byte, Integer, Long, Float, and Double. In addition to this, it also supports the String data type, which can represent alphanumeric values, as well as special characters. To manipulate date and calendar related functionality, DynamoDB provides the Date and Calendar data type also. It also supports BigDecimal and BigInteger data types to support a very large number of numeric values.
These data types are categorized into three types:
- Scalar type: The scalar type represents a single value. The data types such as string, number, boolean, and null come under the scalar type definition.
- Document types: Document types give you key–value pairs of scalar types. It includes list and map types and supports up to 32 levels of nesting. Document types are generally shown in JSON format.
- Set types: Set types can be described as a group of multiple scalar values represented using an array. We have the string set, number set, and binary set.
Now we will discuss each category in detail:
- Scalar types: Scalar types include string, number, boolean, binary, and null values
- String: String types are widely used in programming to represent alphanumeric values, as well as special characters. DynamoDB strings are Unicode with UTF-8 encoding, and should not exceed the size limit of 400 KB. We can also represent the date using a string value.
- Number: Number types represent numerical values, including both positive and negative numbers. We can also use the number data type to represent a floating point number. DynamoDB also supports BigDecimal and BigInteger in the number data type.
- Boolean: Boolean types represent true and false values. Boolean data is very useful in condition-checking and logical operations.
- Binary: Binary types represent any type of binary data, such as images, audio files, videos, encrypted data, or compressed files. DynamoDB treats each byte of binary data as unsigned and has a size limit of 400 KB.
- Null: DynamoDB provides special support for null values. They represent an unknown or undefined state of the attribute.
- Document types: DynamoDB supports two document types: list and map
- List: List types store multiple values in order. Each value is accessible using index, and index starts at zero. We can access the first element using index 0 as list[0]; index 1 represents the second element, and so on. The list is enclosed within square brackets. A list of cities can be written as cities = ["NY", "London", "Paris"].
- Map: Map types are represented as key–value pairs. Each value is accessible using the key. Here, the key must be unique in the keyset of a map. Duplicate keys are not allowed. Maps are enclosed within curly braces. A map of users' age could be written as users = {"john":27, "ryan":34, "smith":28 }.
- Set types: DynamoDB supports sets of number, string, and binary values. Sets are always homogeneous, which means that all elements within the set must be of the same type. Each value within a set must be unique. Also, DynamoDB does not support empty sets. The following are some examples of sets:
- stringSet = ["Black", "Green","Red"]
- numberSet = [42.2, -19, 7.5, 3.14]
- binarySet = ["xy3?=", "UzCPhk=","zj788shbd="]