SMALLINT
16-bit signed integer (SMALLINT) occupies 2 bytes of storage space, suitable for storing integer values ranging from -32768 to 32767. It uses less storage space than INT.
Syntax
SHORT is an alias for SMALLINT, used for compatibility with migration scripts from other databases. Aliases are immediately converted to the canonical type during parsing. See Type Aliases for details.
Value Range
| Boundary | Value |
|---|---|
| Minimum | -32768 |
| Maximum | 32767 |
Literal suffix: S (e.g., 100S, -32768S)
Examples
-
Use the SMALLINT literal suffix:
Returns:
100 -
Cast integers to SMALLINT (boundary values):
Returns:
32767,-32768 -
Cast a string to SMALLINT:
Returns:
1000 -
Overflow behavior (out-of-range values return NULL):
Returns:
NULL -
NULL value handling:
Returns:
NULL
Notes
- The value range is -32768 to 32767. A CAST conversion that exceeds this range returns NULL without raising an error.
- The literal suffix is
S(case-insensitive), e.g.,100S,-32768S. - When SMALLINT participates in arithmetic operations, the result type may be automatically promoted to INT to avoid intermediate overflow.
- For integers outside this range, use
INTorBIGINT. - CAST conversions of invalid strings (e.g.,
'abc') return NULL.
