A 1-byte integer data type used in CREATE TABLE
and ALTER TABLE
statements.
Syntax:
In the column definition of a CREATE TABLE
statement:
column_name TINYINT
Range: -128 .. 127. There is no UNSIGNED
subtype.
Conversions: Impala automatically converts to a larger integer type (SMALLINT
,
INT
, or BIGINT
) or a floating-point type (FLOAT
or
DOUBLE
) automatically. Use CAST()
to convert to STRING
or
TIMESTAMP
.
Casting an integer or floating-point value
N
to TIMESTAMP
produces a value that is
N
seconds past the start of the epoch date (January 1, 1970). By
default, the result value represents a date and time in the UTC time zone. If the
setting ‑‑use_local_tz_for_unix_timestamp_conversions=true
is in effect, the resulting TIMESTAMP
represents a date and time in the
local time zone.
Impala does not return column overflows as NULL
, so that customers can
distinguish between NULL
data and overflow conditions similar to how
they do so with traditional database systems. Impala returns the largest or smallest
value in the range for the type. For example, valid values for a
tinyint
range from -128 to 127. In Impala, a tinyint
with a value of -200 returns -128 rather than NULL
. A
tinyint
with a value of 200 returns 127.
Usage notes:
For a convenient and automated way to check the bounds of the TINYINT
type, call the
functions MIN_TINYINT()
and MAX_TINYINT()
.
If an integer value is too large to be represented as a TINYINT
, use a
SMALLINT
instead.
NULL considerations: Casting any non-numeric value to this type produces a
NULL
value.
Examples:
CREATE TABLE t1 (x TINYINT);
SELECT CAST(100 AS TINYINT);
Parquet considerations:
Physically, Parquet files represent TINYINT
and SMALLINT
values as 32-bit
integers. Although Impala rejects attempts to insert out-of-range values into such columns, if you create a
new table with the CREATE TABLE ... LIKE PARQUET
syntax, any TINYINT
or
SMALLINT
columns in the original table turn into INT
columns in the new
table.
HBase considerations: This data type is fully compatible with HBase tables.
Text table considerations: Values of this type are potentially larger in text tables than in tables using Parquet or other binary formats.
Internal details: Represented in memory as a 1-byte value.
Added in: Available in all versions of Impala.
Column statistics considerations: Because this type has a fixed size, the maximum
and average size fields are always filled in for column statistics, even before you run
the COMPUTE STATS
statement.
Related information:
Numeric Literals, TINYINT Data Type, SMALLINT Data Type, INT Data Type, BIGINT Data Type, DECIMAL Data Type (Impala 3.0 or higher only), Impala Mathematical Functions