INT

Overview

Integer from -2147483648 to 2147483647 when signed, or from 0 to 4294967295 when unsigned.

See also: Data Types in Xpand 6 and in 5.3

DETAILS

SYNONYMS

The following are synonyms for INT:

  • INT4

  • INTEGER

EXAMPLES

SIGNED and UNSIGNED

The INT data type may be SIGNED (allowing negative values) or UNSIGNED (not allowing negative values).

Example of INT SIGNED (SIGNED is the default):

CREATE TABLE int_signed_example (
  description VARCHAR(20),
  example INT SIGNED
);
INSERT INTO int_signed_example VALUES
  ('Zero', 0),
  ('Forty-Two', 42),
  ('Minimum', -2147483648),
  ('Maximum', 2147483647);

Example of INT UNSIGNED:

CREATE TABLE int_unsigned_example (
  description VARCHAR(20),
  example INT UNSIGNED
);
INSERT INTO int_unsigned_example VALUES
  ('Zero', 0),
  ('Forty-Two', 42),
  ('Minimum', 0),
  ('Maximum', 4294967295);

Out-of-Range

A value is considered "out-of-range" when it is too small or too large to be stored in a data type. When SQL_MODE is strict (the default) an out-of-range value generates an error. If strict mode is not in effect, the value is rounded to the nearest valid value without any warnings.

An example of non-strict out-of-range behavior:

TRUNCATE int_signed_example;
TRUNCATE int_unsigned_example;

-- Disable strict mode or the inserts will fail
SET sql_mode=(SELECT REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''));

INSERT INTO int_signed_example VALUES
  ('Underflow', -2147483649),
  ('Overflow', 2147483648);

INSERT INTO int_unsigned_example VALUES
  ('Underflow', -1),
  ('Overflow', 4294967296);

The resulting data would look like this:

SELECT * FROM int_signed_example;
+-------------+-------------+
| description | example     |
+-------------+-------------+
| Underflow   | -2147483648 |
| Overflow    |  2147483647 |
+-------------+-------------+
SELECT * FROM int_unsigned_example;
+-------------+------------+
| description | example    |
+-------------+------------+
| Underflow   |          0 |
| Overflow    | 4294967295 |
+-------------+------------+

INT ZEROFILL

While Xpand accepts the INT ZEROFILL type on table create, the qualifier is silently dropped.

CREATE TABLE int_zerofill_example (
  description VARCHAR(20),
  example INT ZEROFILL
);
SHOW CREATE TABLE int_zerofill_example\G
*************************** 1. row ***************************
       Table: int_zerofill_example
Create Table: CREATE TABLE `int_zerofill_example` (
  `description` varchar(20) CHARACTER SET utf8,
  `example` int(11)
) CHARACTER SET utf8 /*$ SLICES=3 */

CHANGE HISTORY

Release Series

History

6

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.