Si lo hago CAST(1 AS SIGNED INTEGER), siempre termino recibiendo un BIGINTretorno, por ejemplo:
$ mysql -u root -p --column-type-info
Enter password:
--- Copyright and help message snipped for brevity ---
mysql> select cast(1 as signed integer);
Field 1: `cast(1 as signed integer)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: LONGLONG <== LONGLONG i.e. 64 bit integer
Collation: binary (63)
Length: 1
Max_length: 1
Decimals: 0
Flags: NOT_NULL BINARY NUM
+---------------------------+
| cast(1 as signed integer) |
+---------------------------+
| 1 |
+---------------------------+
1 row in set (0.00 sec)
Hubiera esperado que el tipo de retorno de ese elenco fuera un LONG(entero de 32 bits).
Si selecciono una columna de una tabla que tiene un INT, veo que de hecho es solo un LONG:
mysql> describe contact;
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| contact_id | int(11) | NO | PRI | NULL | auto_increment |
== remainder of table snipped ==
mysql> select contact_id from contact where contact_id = 20;
Field 1: `contact_id`
Catalog: `def`
Database: `centreon`
Table: `contact`
Org_table: `contact`
Type: LONG <== LONG i.e. 32 bit integer
Collation: binary (63)
Length: 11
Max_length: 2
Decimals: 0
Flags: NOT_NULL PRI_KEY AUTO_INCREMENT NUM PART_KEY
+------------+
| contact_id |
+------------+
| 20 |
+------------+
1 row in set (0.00 sec)
mysql>
Si lanzo la misma columna a un entero con signo, nuevamente obtengo un entero de 64 bits:
mysql> select CAST(contact_id as signed integer) from contact where contact_id = 20;
Field 1: `CAST(contact_id as signed integer)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: LONGLONG
Collation: binary (63)
Length: 11
Max_length: 2
Decimals: 0
Flags: NOT_NULL BINARY NUM
+------------------------------------+
| CAST(contact_id as signed integer) |
+------------------------------------+
| 20 |
+------------------------------------+
1 row in set (0.00 sec)
Hay un problema similar reportado aquí:
Pero lamentablemente el OP no obtiene una respuesta directa.
¿Es esto un error en la CAST()función o es por diseño?
SIGNED [INTEGER]en la sección El tipo para el resultado puede ser uno de los siguientes valores: . ¿Es un SIGNED INTEGERen el contexto de un CASTno de hecho un entero de 32 bits?
SELECT 1+1resultados en a BIGINT. Pero todavía no explica por qué distancia CAST()se comporta contrariamente a la documentación (como yo lo entiendo) y produce una BIGINTaunque se solicite su elenco de SIGNED INTEGERo UNSIGNED INTEGERen un solo valor escalar.