

# Data Types
<a name="sql-reference-data-types"></a>

The following table summarizes the data types supported by Amazon Kinesis Data Analytics. 


| SQL Data Type | JSON Data Type | Description | Notes | 
| --- | --- | --- | --- | 
|  BIGINT  | number |  64-bit signed integer  | 
|  BINARY  | BASE64-encoded string |  Binary (non character) data  |  Substring works on BINARY. Concatenation does not work on BINARY.  | 
|  BOOLEAN  | boolean |  TRUE, FALSE, or NULL  |  Evaluates to TRUE, FALSE, and UNKNOWN.  | 
|  CHAR (n)  | string |  A character string of fixed length n. Also specifiable as CHARACTER  |  n must be greater than 0 and less than 65535.   | 
|  DATE  | string |  A date is a calendar day (year/month/day).  |  Precision is day. Range runs from the largest value, approximately \$1229 (in years) to the smallest value, -229.  | 
|  DECIMAL DEC NUMERIC  | number |  A fixed point, with up to 19 significant digits.  |  Can be specified with DECIMAL, DEC, or NUMERIC.  | 
|  DOUBLE DOUBLE PRECISION  | number |  A 64-bit floating point number  |  64-bit approx value; -1.79E\$1308 to 1.79E\$1308. Follows the ISO DOUBLE PRECISION data type, 53 bits are used for the number's mantissa in scientific notation, representing 15 digits of precision and 8 bytes of storage.  | 
|  INTEGER INT  | number |   |  32-bit signed integer. Range is -2147483648 to 2147483647 [ 2\$1\$1(31) to 2\$1\$1(31)- 1]  | 
|  INTERVAL <timeunit> [TO <timeunit>]  | string |  Day-time intervals supported, year-month intervals not supported  |  Allowed in an expression in date arithmetic, but cannot be used as a datatype for a column in a table or stream.   | 
|  <timeUnit>  | string |  The units of a INTERVAL value  |  Supported units are YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND  | 
|  SMALLINT  | number |  16-bit signed integer  |  Range is -32768 to 32767  [2\$1\$1(15) to 2\$1\$1(15)-1]  | 
|  REAL  | number |  A 32-bit floating point number  |  Following the ISO REAL data type, 24 bits are used for the number's mantissa in scientific notation, representing 7 digits of precision and 4 bytes of storage. The minimum value is -3.40E\$138; the maximum value is 3.40E\$138.  | 
|  TIME  | string |  A TIME is a time in a day (hour:minute:second).  |  Its precision is milliseconds; its range is 00:00:00.000 to 23:59:59.999. Since the system clock runs in UTC, the timezone used for values stored in a TIME or TIMESTAMP column is not considered. for values stored in a TIME or TIMESTAMP column.  | 
|  TIMESTAMP  | string |  A TIMESTAMP is a combined DATE and TIME.  |  A TIMESTAMP value always has a precision of 1 millisecond. It has no particular timezone. Since the system clock runs in UTC, the timezone used for values stored in a TIME or TIMESTAMP column is not considered. Its range runs from the largest value, approximately \$1229 (in years) to the smallest value, -229. Each timestamp is stored as a signed 64-bit integer, with 0 representing the Unix epoch (Jan 1, 1970 00:00am). This means that the largest TIMESTAMP value represents approximately 300 million years after 1970, and the smallest value represents approximately 300 million years before 1970. Following the SQL standard, a TIMESTAMP value has an undefined timezone.  | 
|  TINYINT  | number |  8-bit signed integer  |  Range is -128 to 127,  | 
|  VARBINARY (n)  | BASE64-encoded string |  Also specifiable as BINARY VARYING  |  n must be greater than 0 and less than 65535.   | 
|  VARCHAR (n)  | string |  Also specifiable as CHARACTER VARYING  |  n must be greater than 0 and less than 65535.   | 
<a name="NOTE1"></a>
**Notes**  
Regarding characters:
+ Amazon Kinesis Data Analytics supports only Java single-byte CHARACTER SETs.
+ Implicit type conversion is not supported. That is, characters are mutually assignable if and only if they are taken from the same character repertoire and are values of the data types CHARACTER or CHARACTER VARYING.

Regarding numbers:
+ Numbers are mutually comparable and mutually assignable if they are values of the data types NUMERIC, DECIMAL, INTEGER, BIGINT, SMALLINT, TINYINT, REAL, and DOUBLE PRECISION.

The following sets of data types are synonyms:
+ DEC and DECIMAL
+ DOUBLE PRECISION and DOUBLE
+ CHARACTER and CHAR
+ CHAR VARYING or CHARACTER VARYING and VARCHAR
+ BINARY VARYING and VARBINARY
+ INT and INTEGER
+ Binary values (data types BINARY and BINARY VARYING) are always mutually comparable and are mutually assignable.

Regarding dates, times, and timestamps:
+ Implicit type conversion is not supported (that is, datetime values are mutually assignable only if the source and target of the assignment are both of type DATE, or both of type TIME, or both of type TIMESTAMP).
+ The Amazon Kinesis Data Analytics timezone is always UTC. The time functions, including the Amazon Kinesis Data Analytics extension CURRENT\$1ROW\$1TIMESTAMP, return time in UTC.

# Numeric Types and Precision
<a name="sql-reference-numeric-types-precision"></a>

For DECIMAL we support a maximum of 18 digits for precision and scale.

Precision specifies the maximum number of decimal digits that can be stored in the column, both to the right and to the left of the decimal point. You can specify precisions ranging from 1 digit to 18 digits or use the default precision of 18 digits.

Scale specifies the maximum number of digits that can be stored to the right of the decimal point. Scale must be less than or equal to the precision. You can specify a scale ranging from 0 digits to 18 digits, or use the default scale of 0 digits.

**Rule for Divide**  
Let p1, s1 be the precision and scale of the first operand, such as DECIMAL (10,1). 

Let p2, s2 be the precision and scale of the second operand, such as DECIMAL (10,3).

Let p, s be the precision and scale of the result. 

Let d be the number of whole digits in the result. Then, the result type is a decimal as shown following:


|  |  | 
| --- |--- |
|  d = p1 - s1 \$1 s2  |  D = 10 - 1 \$1 3 Number of whole digits in result = 6  | 
|  s <= MAX (6, s1 \$1 p2 \$11)  |  S <= MAX (6, 1 \$1 10 \$1 1) Scale of result = 14  | 
|  p = d \$1 s  |  Precision of result = 18  | 

Precision and scale are capped at their maximum values (18, where scale cannot be larger than precision).

Precedence is first giving at least the scale of the first argument (s >= s1) followed by enough whole digits to represent the result without overflow

**Rule for Multiply**  
Let p1, s1 be the precision and scale of the first operand DECIMAL (10,1).

Let p2, s2 be the precision and scale of the second operand DECIMAL (10,3).

Let p, s be the precision and scale of the result. 

Then, the result type is a decimal as shown following:


|  |  | 
| --- |--- |
|  p = p1 \$1 p2  |  p = 10 \$1 10 Precision of result = 18  | 
|  s = s1 \$1 s2  |  s = 1 \$1 3 Scale of result = 4  | 

**Rule for Sum or Subtraction**  
Type-inference strategy whereby the result type of a call is the decimal sum of two exact numeric operands where at least one of the operands is a decimal.

Let p1, s1 be the precision and scale of the first operand DECIMAL (10,1).

Let p2, s2 be the precision and scale of the second operand DECIMAL (10,3).

Let p, s be the precision and scale of the result, as shown following:


|  |  | 
| --- |--- |
|  s = max(s1, s2)  |  s = max (1,3) Scale of result = 3  | 
|  p = max(p1 - s1, p2 - s2) \$1 s \$1 1  |  p = max(10-1,10-3) \$1 3 \$1 1 Precision of result = 11  | 

s and p are capped at their maximum values